ASP.NET 脚本组合

发布于 2024-10-05 08:25:11 字数 773 浏览 4 评论 0原文

我已将 asp:ScriptManager 控件替换为具有 CombineScripts="true" 属性的 ajaxToolkit:ToolkitScriptManager

现在,当我查看 HTML 页面的源代码时,有新的脚本标记:

<script src="/MyPage.aspx?_TSM_HiddenField_=ctl00__pageBody_asScript_tscAjaxScripts_HiddenField&amp;_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

打小就很酷 2024-10-12 08:25:12

在这种情况下,通过设置 ajaxToolkit:ToolkitScriptManagerCombineScripts="true" 意味着这将合并该页面上 ajax 控件使用的所有脚本文件,并且它将加载组合脚本采用以下形式 -

<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" />

但在 ScriptResource.axd 文件中,它将加载 Microsoft Ajax 库文件,例如 -
MicrosoftAjax.debug.jsMicrosoftAjaxWebForms.debug.js 在单独的请求中。
您可以通过组合它们来向 Microsoft Ajax 发出单个请求。

您可以显式使用 标记并指定 MicrosoftAjax.jsWebform.jsMicrosoftAjaxWebForms.debug.js 将它们组合在一个请求中。
这样你只会看到两个 JS 请求,一个是该页面上 Ajax 控件的组合脚本,另一个是 MicrosoftAjax js 的组合脚本

In this scenario by setting CombineScripts="true" of ajaxToolkit: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-

<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 in ScriptResource.axd files it will load the Microsoft Ajax library files like -
MicrosoftAjax.debug.js and MicrosoftAjaxWebForms.debug.js in separate request.
You can make a single request for Microsoft Ajax by combing them.

You can use <CompositeScript> tag explicitly and specify MicrosoftAjax.js,Webform.jsandMicrosoftAjaxWebForms.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

海未深 2024-10-12 08:25:12

我为此编写了一个简单的处理程序,似乎工作正常,但它适用于 ASP.NET MVC,但让它也适用于 Webforms 应该不难。我把它放在github上:https://github.com/mastoj/SimpleCompression

我的解决方案的优点是:

  • 您不需要脚本的两份副本;也就是说,是原始版本的缩小版本。
  • 如果需要,您可以更改压缩引擎。
  • 文件会被即时压缩并放入 webb 服务器和客户端上的缓存中(您可以更新版本设置以强制客户端再次下载脚本)。
  • 这些文件会即时合并。
  • 组合和压缩的文件对原始文件具有文件依赖性,因此如果您出于某种原因需要在产品中测试某些内容(但不要这样做:),它们会被重新压缩和组合。
  • 而且它很容易使用,至少对于 MVC 来说是这样。

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:

  • You don't need two copies of your script; that is, a minified version with the original.
  • You can change compress engine if you want.
  • The files are compressed on the fly and put in the cache on the webb server and client (you can update a version setting to force client to download script again).
  • The files are combined on the fly.
  • The combined and compressed file has file dependency to the original files so they are re-compressed and combined if you for some reason need to test something in prod (but don't do it :)).
  • And it is easy to use, for MVC at least.
尛丟丟 2024-10-12 08:25:12

如果您使用的是 .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...)

ゝ杯具 2024-10-12 08:25:11

AjaxControlToolkit 的某些组件不支持组合脚本。
来自:http://blogs.msdn.com/b/delay/archive/2007/06/11/script-combining-made-easy-overview-of-the-ajax-control -toolkit-s-toolkitscriptmanager.aspx

滑块的 SliderBehavior.js 脚本
使用一个相当晦涩的功能启用
由 PerformSubstitution 属性
WebResource 属性允许
<%= WebResource/ScriptResource %>标签
嵌入到JS文件中并得到
在脚本发送到之前已解决
浏览器。这种行为不是
目前支持
工具包脚本管理器

没有神奇的标志可以打开来完全删除这些文件。使用 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

The Slider's SliderBehavior.js script
uses a fairly obscure feature enabled
by the PerformSubstitution property of
the WebResource attribute that allows
<%= WebResource/ScriptResource %> tags
to be embedded in JS files and get
resolved before the script is sent to
the browser. This behavior isn't
currently supported by
ToolkitScriptManager

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文