jQuery Cookbook - Cdn.oreilly.com - O'Reilly
jQuery Cookbook - Cdn.oreilly.com - O'Reilly
jQuery Cookbook - Cdn.oreilly.com - O'Reilly
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
This eliminates one more server request.<br />
Discussion<br />
One of the keys to fast page loading is to simply minimize the number of HTTP requests.<br />
Making requests to different servers can also help. Browsers will make only a small<br />
number of simultaneous downloads from any single domain (or subdomain), but if you<br />
download some of your files from a different domain, the browser may download them<br />
in parallel as well.<br />
Pointing different tags to different domains may allow them to<br />
be downloaded in parallel, but it doesn’t affect the order of execution.<br />
tags are executed in the order they appear in the HTML source.<br />
You can <strong>com</strong>bine JavaScript files by hand by simply copying and pasting them into one<br />
big file. This is inconvenient for development but does speed up downloading.<br />
There are a number of file <strong>com</strong>biner/minifiers available for various server languages.<br />
Ruby on Rails:<br />
• Bundle-fu<br />
• AssetPackager<br />
• The packager built into Rails 2.0<br />
PHP:<br />
• Minify<br />
Python:<br />
• JSCompile<br />
Java:<br />
• YUI Compressor<br />
In addition to JavaScript code, check your CSS for multiple .css files. Some of the tools<br />
listed can merge your .css files into a single download, just as they do for .js files.<br />
At one time, “packing” JavaScript was all the rage. This not only removes<br />
<strong>com</strong>ments and whitespace but also rewrites all of the JavaScript<br />
code so that it’s not even JavaScript code anymore. Packing requires an<br />
unpacking step at runtime—every time the page loads, even if the Java-<br />
Script code is already cached. Because of this, packing has fallen out of<br />
favor, and “minifying” the code (removing <strong>com</strong>ments and whitespace)<br />
is re<strong>com</strong>mended instead, <strong>com</strong>bined with gzip <strong>com</strong>pression. Much of<br />
the benefit of packing <strong>com</strong>es from removing duplicate strings, and gzip<br />
does that for you anyway.<br />
5.18 Making Fewer Server Requests | 125