Proper way to include scripts in an asp.net page

后端 未结 3 1088
暗喜
暗喜 2021-01-11 18:11

I\'ve got an ASP.NET application that uses a mixture of ASP.NET AJAX (Including UpdatePanel) and jQuery written by several developers of differing backgrounds.

Some

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-11 19:03

    It's not always possible to include all script in the markup.
    If the script depends on dynamic data then you'll need to "inject" the script from the code behind.

    My rule is to always try to avoid "injecting" script from code behind if possible and only use that as a last resort.

    Edit:
    Using scriptmanager is prefered if you have many different script files.
    When using scriptmanager all scripts will be "concatenated" into a single file. This has an impact on how the browser downloads the scripts. Browsers usually have a limit of 2 concurrent connections and if you have 10 scripts then you'll need to download them all in 5 steps. Scriptmanager will see to it that it all happens in a single step.

提交回复
热议问题