Search code examples
javascriptasp.netwebresource.axdscriptresource.axd

ASP.NET Script combining


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

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?


Solution

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