nii*_*ico 5 asp.net webforms asp.net-4.5
我创建了一个新的 ASP.NET 4.5.1 Web 表单项目。
母版页中有一个脚本管理器——它列出了大量的脚本,包括对 jquery 和 bootstrap 的引用:
<asp:ScriptManager runat="server">
<Scripts>
<%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%>
<%--Framework Scripts--%>
<asp:ScriptReference Name="MsAjaxBundle" />
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="bootstrap" />
<asp:ScriptReference Name="respond" />
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
<asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
<asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
<asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
<asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
<asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
<asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
<asp:ScriptReference Name="WebFormsBundle" />
<%--Site Scripts--%>
</Scripts>
</asp:ScriptManager>
Run Code Online (Sandbox Code Playgroud)
这些脚本然后包含在页面中。
我一直认为脚本管理器只是针对 AJAX 相关的脚本,但现在它似乎包括了所有的 js 脚本。它似乎也与 Bundling & Minification 冲突——因为它包含脚本而不是包引用。
我已经搜索过谷歌,但无法找到脚本管理器实际上超出了它与 AJAX 的关系。
更新
我找到了对脚本管理器的脚本属性的引用,尽管它没有解释列出所有页面脚本的好处/原因:http : //msdn.microsoft.com/en-us/library/system.web .ui.scriptmanager.scripts(v=vs.110).aspx
这两个功能确实可以协同工作,因为捆绑脚本和管理脚本是两个独立的任务。捆绑显然是两者中更简单的一种,因为它只是指将多个脚本文件合并为一个的技术,以便通过减少对服务器的必要请求数量来提高性能。但是,有完全正当的理由让 ScriptManager 处理捆绑的 JavaScript 文件(以及组成它们的脚本)以及非捆绑的文件。例如,您可以使用 ScriptManager 在调试模式下加载非缩小脚本和发布模式下加载缩小脚本之间切换。您还可以指定 LoadSuccessExpression,它将用于检查脚本是否已正确加载,如果不正确,则可以根据 CdnPath 属性从 CDN 加载脚本。这些将在 ScriptResourceDefinition 中指定,可能在 App_Code/BundleConfig.cs 或 Global.asax 中,但您仍然希望将 ScriptReference 元素添加到 ScriptManager。