If you’re using Apache and PHP 5.3 on your DreamHost domain, you have the magical power to enable Google PageSpeed. Just go and edit your domain and make sure you check the box for “Page Speed Optimization”:
But what does that even mean, I hear you ask?
PageSpeed is Google’s way to speed up the web (yeah, that was redundant), and it serves as a way for your server to do the work of caching and compressing, taking the load off your webapps. Like WordPress. Anyone can install this on their apache server, and it’s free from Google Developers: PageSpeed Mod. Since you’re on DreamHost, you lucky ducky you, we did it for you. Now you can sit back and relax.
The first thing to notice when you turn on PageSpeed is that it minifies your webpage. That means it takes your pretty formatted source code and gets rid of the extra spaces you don’t use. This is called by using the PageSpeed filter “collapse_whitespace.” Another filter we use is “insert_ga” which is how we’re magically able to insert your Google Analytics for you from your panel. That filter automatically inserts your GA code on every page on your domain. That’s right! No more plugins!
If you’re like me, you may start to wonder what other filters you should use, and that entirely depend on what you want to remove. I knew I wanted to remove code comments like the following:
<!-- #site-navigation -->
That’s easy! There’s a filter for “remove_comments” so I can just use that. They have a whole mess of filters listed in the Filter Documentation and reading through it took a while. If you read each one, at the bottom they talk about how risky a certain filter is. Taking that into account, I went ahead and added some low and some high risk filters, since I know what I’m using.
The magic sauce to add all this is just to edit your .htaccess and put in the following near the top:
<IfModule pagespeed_module> ModPagespeed on ModPagespeedEnableFilters remove_comments,rewrite_javascript,rewrite_css,rewrite_images ModPagespeedEnableFilters elide_attributes,defer_javascript,move_css_to_head ModPagespeedJpegRecompressionQuality -1 </IfModule>
Really, that’s it.
The ones I picked are:
- remove_comments – Remove HTML comments (low risk)
- rewrite_javascript – minifies JS (med. to high risk, depending on your site)
- rewrite_css – parses linked and inline CSS, rewrites the images found and minifies the CSS (med. risk)
- rewrite_images – compresses and optomizes images (med. risk)
- elide_attributes – removing attributes from tags (med. risk)
- defer_javascript – combines JS and puts it at the end of your file (high risk AND experimental!)
- move_css_to_head – combines CSS and moves it to the head of your file (low risk)
Now keep in mind, not all of the features will work. While DreamHost is on a pretty cutting edge version of PageSpeed, they’re constantly innovating over there and improving. The best thing about these changes is, if you do it right, you can speed your site up faster than any plugin could do for you. And that? Is pretty cool right there.