dans.blog


The miscellaneous ramblings and thoughts of Dan G. Switzer, II

A "safe" way to compress your JavaScript code...

If you ever do any heavy JavaScript development, you know how large cross browser libraries. The file sizes of these libraries get very large, very quickly. Usually JavaScript files contain a lot of whitespacing and (hopefully) commenting, which can drastically increase the file size—which means for longer download times.

There are many solutions to this problem, but most involve the basic idea of stripping out commenting and taking out the unneccesary whitespacing. While these simple steps can reduce you files nicely, there are better ways.

Alex Russell, the project lead for the Dojo JavaScript Toolkit, has written an open source compression tool called SourceSafe. SourceSafe is based on Rhino, the JavaScript engine used in the Mozilla projects.

more…