Embedding & Compiling Minified.js

Why should I embed Minified.js?

The easiest way to use Minfied is the traditional way, just add a script tag on your page and point it to one of the precompiled versions that you can download:

<script type="text/javascript" src="path/to/minified.js"></script>
This is not only the simplest way to use Minified, it's also by far the quickest way to get started.

However, if your goal is to optimize your site for download size or page load time, it's often better to combine all your source file into a single file. Using a single file has several advantages:

  • The browser only needs a single HTTP requests, reducing load time.
  • If you compile your source code using a compiler/minification tool such as Google Closure, UglifyJS or YUI Compressors, they will work better with a single file.
  • Gzip compression is also more efficient when you have a single large JavaScript file, as opposed to several small ones.

How can I embed Minified.js?

Embedding Minified can be as easy as taking the content of a Minified source file and copying it at the top of your source code. Usually this is not practical though. Unless only have a few lines of code and can live with scrolling down to edit your own code, you need to set up a small build system that combines several source files into a single result file. On the command line, a cat command should be sufficient for that. When you use a compiler like Google Closure or UglifyJS, they are usually already capable of combining files.

How can I compile Minified.js with Closure?

Most compilers / minification tools will work just fine with Minified.js, but there is one exception: the Google Closure Compiler with Advanced Optimization. While Closure's Simple Optimization does not cause any problem, the Advanced Optimization options require a lot of annotations to work correctly for a library. The compilation process removes the annotations and thus, if you want to embed Minified and use Advanced Optimizations, you must use the plain source code version of Minified.

How can I compile Minified.js with UglifyJS / YUI Compressor / Closure Simple Optimization?

You can embed and compile both the plain source versions and the pre-compiled release of Minified. However, unless you are using Google Closure, I recommend using the pre-compiled version, as the other tools can't reduce the size as much as Closure's Advanced Optimization. Compiling twice does not hurt as long as you don't use Closure Advanced Optimization twice. In fact, the offical Minifed releases are also compiled twice.

How are Minified's releases compiled?

The compiled versions of Minified.js are first compiled with the Google Closure Compiler with Advanced Optimization, and the result is then compiled again using UglifyJS. In the first step, the size is reduced from over 100kb to about 9kb. In the second step, UglifyJS removes about 80 bytes. After GZip'ing the difference is only about 30 bytes.
If you are using the builder tool, only Google Closure is used. That's why the builder creates slightly larger files.

back to Minified documentation.