|
|
Compressing WebResource.axd To Reduce Your Website Size
By Mads Kristensen
Expert Author
Article Date: 2008-06-20
A lot have been written about the compression of WebResource.axd over the years, but as far as I know, nobody has come up with a simple solution to it.
Miron Abramson does have a very good library for compressing a lot of different file types, but I've never been much in favour of third-party libraries.
There are several reasons why you want to compress the WebResource.axd. First of all you want to reduce the size of your website. On this blog ASP.NET inserts two WebResource.axd script with a combined file size of 43.3KB. If I use compression and minify the scripts, the total file size will be 8.1KB. That is a significant gain.
The WebResource.axd is cached in the browser until midnight the same day, so the file size might not be that big a deal. Well, if we can make it expire on a much later date it would be much better since it never changes. So, if the WebResource.axd is minified, compressed and set to live longer in the browsers it really adds up.
Implementation
Download the CompresWebResource.cs file below and put it in your App_Code folder. Then add the following lines to your web.config:
You can use the HttpHandler for all your other .js files as well. Just change the path from /script.js to js.axd?path=/script.js.
Download
CompressWebResource.zip (2,81 kb)
Comments
About the Author: Mads Kristensen currently works as a Senior Developer at Traceworks located
in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in
2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and
web services in his daily work as well. A true .NET developer with great passion for the simple solution.
http://www.madskristensen.dk/
|
|