Minify your JavaScript - and save the KB's for later (Imtech JavaScript Minificator - Free Tool)
Recently I have spent quite some time measuring and tuning the performance of the Imtech SharePoint Enhancement Toolkit: a toolkit that I have built in order to achieve standards compliancy, accessibility and slightly more performance of SharePoint Web Content Management (WCM) solutions.
During my tests I have stumbled upon an article of Robert Nyman about YSlow - a performance measurement Firefox add-in: Improve Your Web Site Performance - Tips & Tricks To Get A Good YSlow Rating. Because the tool presents not only the test results, but also helps you fixing the discovered issues, you should definitely be careful and make educated choices rather than fixing everything on your way. One of the aspects YSlow measures is whether the JavaScript are minified: are all the indents and line breaks removed in order to keep the file size low.
YSlow suggests two services which can minify your JavaScript: JSMin and (of course) YUI Compressor by Yahoo. Both tools are command-line tools, which minify whole JS files. YUI Compressor provides you an option to minify the CSS files as well.
While you could just minify all your JS files manually in every WCM project you’re working on, I’d rather have it done automatically so I could work with human readable files in the development and serve them minified to the visitors. That’s when the problems start.
Not every JavaScript file can be minified. In order to minify a JavaScript file (or script) each line has to end either with an operator or semicolon. Having implemented the JavaScript minifier in the Imtech SharePoint Performance Toolkit I have discovered that the SharePoint JavaScript files don’t support it. And it’s a pity, because having the SharePoint JS files would spare about 10%-15% (about 30KB) per file!
Looking on the Internet for a Windows App which would help me minify my JavaScript files I have stumbled upon the JavaScript Minifier - a utility by Rick Strahl.
It’s a really great tool. It allows you to either minify a single JavaScript file or a complete directory. However, while using it, I have found out that I would like to have the ability to paste JavaScript scripts and have them minified as well.
I have put the missing functionality into the Imtech JavaScript Minificator. Both tools work using the JavaScriptMinifier class by Douglas Crockford.
Imtech JavaScript Minificator is a free utility and you can use it without any restrictions.
Download: Imtech JavaScript Minificator v1.0.0.0 (31KB)