Minify!
Minify is a PHP5 app that can combine multiple CSS or Javascript files, compress their contents (i.e. removal of unnecessary whitespace/comments), and serve the results with HTTP encoding (gzip/deflate) and headers that allow optimal client-side caching. This helps you follow several of Yahoo!'s Rules for High Performance Web Sites. (See "Problem Domain" below for more info.)
| Before | |
| After | |
The default installation is similar to Yahoo's Combo Handler Service, except that Minify can combine any local JS/CSS files you need for your page.
News
2009-06-30 Minify 2.1.3 released, fixing some CSS and HTTP bugs (notably improving caching in webkit browsers). See History for more details.
2009-03-01 Minify 2.1.2 released, mainly to fix a few bugs and add FirePHP-based error logging.
Features
- Combines and minifies multiple CSS or JavaScript files into a single download
- Uses an enhanced port of Douglas Crockford's JSMin library and custom classes to minify CSS and HTML
- Caches server-side to avoid doing unnecessary work
- Responds with an HTTP 304 (Not Modified) response when the browser has an up-to-date cache copy
- Most modules are lazy-loaded as needed (304 responses use minimal code)
- Automatically rewrites relative URIs in combined CSS files to point to valid locations
- With caching enabled, Minify is capable of handling hundreds of requests per second on a moderately powerful server.
- Content-Encoding: gzip, based on request headers. Caching allows it so serve gzipped files faster than Apache's mod_deflate option!
- Test cases for most components
- Easy integration of 3rd-party minifiers
- Separate utility classes for HTTP encoding and cache control
Requirements
- PHP 5.1.6.
- The commonly installed zlib extension is recommended for HTTP encoding functionality.
- Version 1.0.1 required PHP 5.2.1+.
Installation
See the README.txt file of the appropriate release or the UserGuide.
Support List
PHP5 Component Classes
Minify is based on several PHP5 classes that may be useful in other projects (all BSD licensed).
Warning
Minify is designed for efficiency, but, for very high traffic sites, Minify may serve files slower than your HTTPd due to the CGI overhead of PHP. See the FAQ for more info.
Problem Domain
Pages that refer to multiple CSS or JavaScript files often suffer from slower page loads, due to the browser requesting each file individually. Many browsers also are limited to a few simultaneous requests per domain. The wait for a series of requests and the transfer of unoptimized files can dramatically reduce the client-side performance of your site.
Here are some of Yahoo!'s best practices that are addressed by the use of Minify.
- Make Fewer HTTP Requests
- Add an Expires or a Cache-Control Header
- Gzip Components
- Minify JavaScript and CSS
- Configure ETags
- Keep Components under 25K
Acknowledgments
Minify was inspired by jscsscomp by Maxim Martynyuk and by the article 'Supercharged JavaScript' by Patrick Hunlock.
The JSMin library used for JavaScript minification was originally written by Douglas Crockford and was ported to PHP by Ryan Grove specifically for use in Minify.
You may contact Steve Clay (steve@mrclay.org) or Ryan (ryan@wonko.com) if you're interested in joining the project.