HTML and CSS Reference
In-Depth Information
Minification
The need for JavaScript and CSS compression to keep bandwidth and page load times
as small as possible is becoming more important to ensuring faster load times and more
enjoyable user experiences. Minification is the process of removing all unnecessary
characters from source code, without changing its functionality.
JavaScript and CSS resources may be minified, preserving their behavior while consid‐
erably reducing their file size. Some libraries also merge multiple script files into a single
file for client download. This fosters a modular approach to development and limits
HTTP requests.
Google has released its Closure Compiler tool, which provides minification as well as
the ability to introduce more aggressive renaming. It also can remove dead code and
provide function inlining. In addition, certain online tools, such as Microsoft Ajax
Minifier, the Yahoo! YUI Compressor, and Pretty Diff, can compress CSS files. Some of
your choices are:
JSMin
JSMin is a conservative compressor, written several years ago by Douglas Crockford.
It is a filter that removes comments and unnecessary whitespace from JavaScript
files. It typically reduces file size by half, resulting in faster downloads. It also en‐
courages a more expressive programming style, because it eliminates the download
cost of clean, literate self-documentation. It's recommended you use JSLint before
minimizing your JavaScript with JSMin.
Packer
Packer, by Dean Edwards, is also a very popular JavaScript compressor, which can
go beyond regular compression and also add advanced on-the-fly decompression
with a JavaScript runtime piece. For example, Packer can optionally base64 com‐
press the given source code in a manner that can be decompressed by regular web
browsers, as well as shrink variable names that are typically 5 to 10 characters to
single letters, which reduces the file size of the script and, therefore, makes it down‐
load faster.
Dojo ShrinkSafe
Dojo ShrinkSafe is a very popular Java-based JavaScript compressor that parses the
JavaScript using the Rhino library and crunches local variable names.
YUI Compressor
The YUI Compressor is a newer compressor written by Julien Lecomte that aims
to combine the safety of JSMin with the higher compression levels achieved by Dojo
ShrinkSafe. Like Dojo ShrinkSafe, it is written in Java and based on the Rhino library.
Search WWH ::




Custom Search