@Html.Script(ScriptRef.JQuery, "top") - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

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

  • @Html.Script(ScriptRef.JQuery, "top")
  • 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...???

  • An answer to this would be great!
  • 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.

  • 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.

  • 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.