Tonight, me and a couple of friends watched Munich. We were looking forward to seeing it, hoping it would have some of the same qualities as Schindler's List. But it didn't. It was one of the most boring movies I have ever seen. Why did Spielberg pick this particular subject to make a movie about? It is not that interesting. He tries to make it a personal journey for the main charactors, but he totally fails in making them interesting enough to make us care. Spielberg, you can do better.
There is a lot of whitespace in both stylesheets and JavaScript files. This is because of indented text and line breaks to name a few. They are typically also filled with comments to make them more maintainable. Believe it or not, it all adds up substantially to the overall file size. My tests show that stylesheets can be reduced by more than 30% and JavaScript files by 20%. That’s a lot.
I made two C# classes, which implement the IHttpHandler interface, one for stylesheets and one for JavaScript files. The easiest way to implement them is simply to add this line to the <system.web> section of the web.config.
<httpHandlers>
<add verb="*" path="*.js" type="ScriptHandler" validate="false"/>
<add verb="*" path="*.css" type="CssHandler" validate="false"/>
</httpHandlers>
You also have to make sure that the IIS lets the ASP.NET ISAPI filter handle files with .css and .js extensions.
The classes use regular expressions to remove whitespace and comments. Then it caches the cleaned file and adds a dependency to the real .css/.js file on disk. Every time you change the source file, the cache reloads.
In order to remove comments properly, you should use the /* … */ syntax and not //. Further more, it can be a problem for the JavaScript handler if a line isn’t closed with a semicolon. Enjoy.
httphandlers.zip (1,95 KB)