ASP.NET 脚本组合
我已将 asp:ScriptManager
控件替换为具有 CombineScripts="true"
属性的 ajaxToolkit:ToolkitScriptManager
。
现在,当我查看 HTML 页面的源代码时,有新的脚本标记:
<script src="/MyPage.aspx?_TSM_HiddenField_=ctl00__pageBody_asScript_tscAjaxScripts_HiddenField&_TSM_CombinedScripts_=%3b%3bAjaxControlToolkit%2c+Version%3d3.0.20820.30277%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3aen-US%3a06e896ab-1f8c-4bcb-9cc4-0200671cba8a%3ae2e86ef9%3a1df13a87%3ac4c00916%3aaf22e781%3a9ea3f0e2%3ac7c04611%3acd120801%3a3858419b%3a96741c43%3a38ec41c0" />
但仍然是旧的脚本标记:WebResource.axd
和几个 ScriptResource.axd
我如何删除 <页面中的 code>WebResource.axd 和 ScriptResource.axd
链接?
I have replaced my asp:ScriptManager
control with ajaxToolkit:ToolkitScriptManager
with attribute CombineScripts="true"
.
Now when I view source of HTML page, there is new script tag:
<script src="/MyPage.aspx?_TSM_HiddenField_=ctl00__pageBody_asScript_tscAjaxScripts_HiddenField&_TSM_CombinedScripts_=%3b%3bAjaxControlToolkit%2c+Version%3d3.0.20820.30277%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3aen-US%3a06e896ab-1f8c-4bcb-9cc4-0200671cba8a%3ae2e86ef9%3a1df13a87%3ac4c00916%3aaf22e781%3a9ea3f0e2%3ac7c04611%3acd120801%3a3858419b%3a96741c43%3a38ec41c0" />
But also are still old script tags: WebResource.axd
and several ScriptResource.axd
How do I remove WebResource.axd
and ScriptResource.axd
links from the page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在这种情况下,通过设置
ajaxToolkit:ToolkitScriptManager
的CombineScripts="true"
意味着这将合并该页面上 ajax 控件使用的所有脚本文件,并且它将加载组合脚本采用以下形式 -但在 ScriptResource.axd 文件中,它将加载 Microsoft Ajax 库文件,例如 -
MicrosoftAjax.debug.js
和MicrosoftAjaxWebForms.debug.js
在单独的请求中。您可以通过组合它们来向 Microsoft Ajax 发出单个请求。
您可以显式使用
标记并指定MicrosoftAjax.js
、Webform.js
和MicrosoftAjaxWebForms.debug.js 将它们组合在一个请求中。
这样你只会看到两个 JS 请求,一个是该页面上 Ajax 控件的组合脚本,另一个是 MicrosoftAjax js 的组合脚本
In this scenario by setting
CombineScripts="true"
ofajaxToolkit:ToolkitScriptManager
means this will combine all the script files used by the ajax controls on that page, and it will load the combined script in the below form-But in
ScriptResource.axd
files it will load the Microsoft Ajax library files like -MicrosoftAjax.debug.js
andMicrosoftAjaxWebForms.debug.js
in separate request.You can make a single request for Microsoft Ajax by combing them.
You can use
<CompositeScript>
tag explicitly and specifyMicrosoftAjax.js
,Webform.js
andMicrosoftAjaxWebForms.debug.js
to combine them in a single request.In this way you will see only two request for JS, one for combined script of Ajax controls on that page and another for combined script MicrosoftAjax js
我为此编写了一个简单的处理程序,似乎工作正常,但它适用于 ASP.NET MVC,但让它也适用于 Webforms 应该不难。我把它放在github上:https://github.com/mastoj/SimpleCompression。
我的解决方案的优点是:
I wrote a simple handler for this that seems to work fine, but it is for ASP.NET MVC, but it shouldn't be that hard to make it work for webforms too. I put it on github: https://github.com/mastoj/SimpleCompression.
The good parts with my solution are:
如果您使用的是 .NET 4.0,则可以使用 scriptmanager 上的enablecdn 属性,它会从 Microsoft 的 CDN 提供所需的 JavaScript 代码。
如果没有,您仍然可以按照 Scott Hanselman 此处的描述合并它们。您还可以更进一步,使用 HTTP 模块/过滤器将这些脚本(WebResource.axd、ScriptResource.axd)组合成 2 个或 3 个脚本,但这需要对 ASP.NET 基础有广泛的了解;否则,您可能会破坏应用程序中的 Microsoft Ajax 方法调用(这是因为 UpdatePanel 使用那些奇特的机制来更新页面的一部分等......)
If you are using .NET 4.0, you could use the enablecdn attribute on the scriptmanager, and it serves the required JavaScript code from the Microsoft's CDN.
If not, you can still merge them as Scott Hanselman describes here. You can also go one step further and use an HTTP Module/Filter to combine those scripts (WebResource.axd, ScriptResource.axd) into 2 or 3 ones, however, it needs an extensive knowledge of ASP.NET foundation; Or else, you could break the Microsoft Ajax method calls in the app (it's because of those fancy mechanism UpdatePanel uses to update a portion of the page, etc...)
AjaxControlToolkit 的某些组件不支持组合脚本。
来自:http://blogs.msdn.com/b/delay/archive/2007/06/11/script-combining-made-easy-overview-of-the-ajax-control -toolkit-s-toolkitscriptmanager.aspx
没有神奇的标志可以打开来完全删除这些文件。使用 ToolKitScriptManager 的优点是,它将减少页面所需的资源数量,从而提高性能。 Webresource.axd 和 Scriptresouce.axd 文件由整个应用程序使用,而不仅仅是 AjaxControlToolkit。我的建议是使用像 Fiddler 这样的程序来查看 Scriptresource.axd 和 Webresource.axd 实际上正在拉入哪些资源并从中工作。
There are some components of the AjaxControlToolkit that do not support combining scripts.
From: http://blogs.msdn.com/b/delay/archive/2007/06/11/script-combining-made-easy-overview-of-the-ajax-control-toolkit-s-toolkitscriptmanager.aspx
There's no magical flag you can turn on to completely get rid of these file. The advantage of using the ToolKitScriptManager is that it will reduce the number of resources your page requires, leading to better performance. The Webresource.axd and Scriptresouce.axd files are used by the entire application, and not just the AjaxControlToolkit. My advice would be to use a program like Fiddler to see what resources the Scriptresource.axd and Webresource.axd are actually pulling in and work from there.