Well, it only took me 18 months, but I finally got around to cleaning up and publishing the Phing filters we use to automatically transform a static site into one that implements many of Yahoo’s Exceptional Performance Rules. These filters, together with the Apache configurations in the README, implement the process outlined in this talk from php|works 2008:
To see it in action, first create an VirtualHost pointing to the mysite directory in the project as the web root. Then run:
% phing optimize
which creates a parallel site in a build directory. Point your VirtualHost to the new build directory to see the same site with the performance transformations.
You could run this Phing task in a continuous integration process as part of deployment. You could run it at production deployment time, but it’s probably a good idea to run it at staging time in case it flubs on some CSS or HTML syntax that it is not expecting.
Note that there are other miscellaneous Phing tasks in that github project. I threw these in there in case they could be of use to other Phing users.
Editor’s note: This post formed the basis of the Front-End Optimization talk I’ve given in the past.
You’ve programmed websites for years, know the ins & outs of PHP, MySQL, why are Javascript and CSS files such a big deal? You put them in a directory, and link to them from your pages. Done. Right?
Not if you want maximum performance.
According to the Yahoo Exception Performance team:
…Only 10% of the time is spent here for the browser to request the HTML page, and for apache to stitch together the HTML and return the response back to the browser. The other 90% of the time is spent fetching other components in the page including images, scripts and stylesheets.
So static content is very important. The same Yahoo people provide us with a comprehensive list of Best (Front-end) Practices for Speeding Up Your Website. IMO, some of the rules are more important than others, and some are more easily achieved. Leaving aside hardware solutions (static server, CDN, etc.) for now, let’s look at six of the rules:
mod_deflate in Apache. Rule 3 is a matter of configuring Apache. How to achieve the other five?
As I see it, there are three broad ways to achieve them.
<link rel="stylesheet" type="text/css" href="custom_handler.php?file1.css,file2.css" /> or something like that). It can also mean using mod_rewrite to direct incoming requests for CSS and Javascript to go to a PHP script. Either way, there is processing on every page load. Caching the end-product helps. Still, there must be a better way. Don’t have a build server? That’s a whole other topic.