The Minify Library

 

After last week’s post highlighting the YSlow Firefox extension, I’ve decided to follow up on the topic of best practices with a brief post on the Minify Library.  The Library was discovered when one of my coworkers was tasked with reducing the http requests of our various sites.  Minify takes cares of that, and much more!

Written using PHP and a Solar framework component, Minify handles removal of whitespace, compression, and header caching of your site’s Javascript and CSS files.  Calls to the library are typically handled one of two ways:

1) Using the link tag’s href attribute, a query string is passed to Minify instead of the usual CSS file.

<link type="text/css" rel="stylesheet" href="/min/b=webroot_dir&amp;f=file1.css,file2.css,file3.css,filen.css" />

Where b is your base path from the web root and f is a comma-separated list of files.

2) Edit a group config file in the min root, adding groups of files to an array key.

'cssfiles' => array('//path/to/file1.css', '//path/to/file2.css', '//path/to/filen.css')

<link type="text/css" rel="stylesheet" href="/min/g=cssfiles" />

Where the config file consits of  ‘cssfiles’  (an array key to identify the list), the file list in its own numerically indexed array, and the HTML link tag now uses a query string with g for the group identifier (cssfiles).

The output of Minify will be a single CSS include stripped of all whitespace and serving all listed files with compression.  The results are astounding – in some of our cases cutting files to 1/10 their original size, and reducing load times by several seconds!

If you run a CSS or JS heavy site, and want to keep a good file structure AND fast load times, a library such as this is indispensable.  Maybe your site already loads pretty fast, but you just really want to squeeze those extra milliseconds out of the equation – give it a whirl and see what happens.  If you’re like me, and are a stickler for making the best site using the best practices, Minify is a giant leap in the right direction.

  1. No Comments