@Html.Script(ScriptRef.JQuery, "top")

Posted by Community Admin on 05-Aug-2018 16:25

@Html.Script(ScriptRef.JQuery, "top")

All Replies

Posted by Community Admin on 04-Jun-2015 00:00

Can someone please tell me how this all works?

 Lets say in my layout I have 

@Html.Script(ScriptRef.JQuery, "bottom")

But every widget has

@Html.Script(ScriptRef.JQuery, "top")

...am I getting 2 jQuery instances loaded...or can it be defaulted to bottom, or does top override it...???

Posted by Community Admin on 07-Jun-2015 00:00

An answer to this would be great!

Posted by Community Admin on 08-Jun-2015 00:00

You can test this out by adding multiple references to the same script on a page and watching the ​generated HTML.

 

The script will only be added to the page once, not once in each section. The section that it renders in appears to always be the first section in the document that it was added to. For example, if you added jQuery to "top" and "bottom" it will add the script tag to the "top" section and will not duplicate it further down the page where the "bottom" section is.

Posted by Community Admin on 08-Jun-2015 00:00

Yeah it's only once, but it seems that it should send it to whichever comes first, which is just what I'd like clarified...

github.com/.../ResourceRegister.cs

 Looks like once it registers in a section, all other sections are ignored.​  So if "bottom" came first somewhere, then it becomes bottom globally.

Posted by Community Admin on 08-Jun-2015 00:00

It puts the script block in the section declared first in the page markup. It doesn't matter which order you place the script references themselves in. What I mean by this is that

 

@Html.Script(ScriptRef.JQuery, "top")

@Html.Script(ScriptRef.JQuery, "bottom")

 - AND -

@Html.Script(ScriptRef.JQuery, "​bottom")
@Html.Script(ScriptRef.JQuery, "top")

 

both produce the same result. The script reference is included in the "top" section, since it is the first section declared in the page.

This thread is closed