JavaScript minimisation

An important part of any web project is to minimise your JavaScript, reducing loading times from downloading the scripts to the browser. We were using Packer for .NET, which supports modes for packing (compressing the JavaScript into a packed function, which then needs to be run on the client to decompress the JavaScript), and minimisation (where comments, whitespace, unrequired/unreachable code is stripped out, leaving only necessary characters). However, it has the annoying habit of prepending a comment to every processed JS file telling us that this magic was performed by Packer for .NET, which is perhaps forgiveable, but also includes a comment with the path to the original source file, which seems crazy and in our case was exposing internal server names. As well as being irritating this also added unnecessary content to the JS files, which the whole process of minimisation was trying to avoid! I searched and couldn’t find any command line options to turn this off, so I looked for alternatives, and found the Microsoft AJAX Minifier, which is easy to use and performs good quality minimisation without any such annoying comments.

On a side note, I prefer minimisation since packing requires additional processing at the client side which can slow the page load, especially for browsers with poorer JS performance. For minimisation to be most effective, it’s best to first pass the JS code through a verifier such as JavaScript Lint, a good idea anyway for good quality JS code.

Something to add?

This site uses Akismet to reduce spam. Learn how your comment data is processed.