First off, I have to say that most of the work that went into this project was already done for me by someone named rgrove. You can find the original (PHP 5) version of Minify here. All I’ve done is convert the code to run on servers still using PHP 4 (download here). This article presents a justification for using Minify over other techniques, and the results of converting www.appelrouthtutoring.com to use the library.
One solution is caching these files, but this still requires an HTTP connection every time the browser has to check for the latest versions. You could use an expiration time far off in the future, but you better make sure your code works perfectly the first time a user downloads it. Another problem with this technique is that pages served over HTTPS will never be cached; obviously for security reasons.
That would be a good average time for a content heavy site like www.cnn.com, but not for the super simple mostly text web site I tested. After uploading the site using my modified Minify library, the average load time dropped to 1.228 seconds. Again, that’s an average after 10 reloads with no caching. That’s a speedup of 272%(!), with absolutely no effect on the development process for the site.
I found a similar speedup on the intranet part of the site. Load time fell from an average of 4.994 seconds to 2.329 seconds (214% speedup!). While this doesn’t exactly double the productivity of employees using the intranet, it sure makes life a lot easier.
It’s code time (the exact code I use on the homepage):
[do this before writing any HTML]
// Create new Minify objects.
$minifyCSS = new Minify(TYPE_CSS);
$minifyJS = new Minify(TYPE_JS);
// Specify the files to be minified.
// Full URLs are allowed as long as they point
// to the same server running Minify.
[do this in ]
It’s so easy, it should be a crime to load multiple external files the old-fashioned way. Let’s all make the web a better place and start cutting down those load times!