0

I need to have scripts at the top and bottom of my page. Telerik uses the ScriptRegistrar and for the javascript this only works if placed at the bottom of the file (just before the </body>)

I also want to use the Telerik built-in minifier/compressor.

So, say in the head of my page I need jQuery and an arbitrary javascript file, and at the bottom do the Telerik references, how would I use the ScriptRegistrar to do this?

So far I have this but it results in duplicate output, and both script tags are at the end of the page:

Head:

@(Html.Telerik().ScriptRegistrar().Scripts(scripts => scripts.AddGroup("Common", group => group
    .Add("...")
    .Add("...")
    .Add("...")
    .Combined(true).Compress(true)
  )).DefaultGroup(group => group.Combined(true).Compress(true)) 
)

Before </body>:

@(Html.Telerik().ScriptRegistrar().jQuery(false).jQueryValidation(false)
  .DefaultGroup(group => group.Combined(true).Compress(true))
)

Any ideas?

TIA

1 Answer 1

1

The issue is that you are using the razor output tag on the latter script registrar.

So it includes it in the group to be rendered and then renders it again.

You need to put the latter script registrar a code block

@ {
Html.Telerik().ScriptRegistrar().jQuery(false).jQueryValidation(false)
  .DefaultGroup(group => group.Combined(true).Compress(true));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.