Kick PageSpeed Up A Notch

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”:

PageSpeed Option

But what does that even mean, I hear you ask?

partnersPageSpeed 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.

Comments

  1. Prayers and Apples says

    Trying this right now – should I delete my Google Analytics plug-in that was previously installed? (And does that mean I should click “Google Analytics” under Web Options?) Also: will I still see benefits if all I do is check “Page Speed Optimization”? I’m afraid to mess with anything else since I don’t really know what I’m doing! And one more question: is there anyway this could mess up the format/how things look on my site – is there anything I should look out for?

    • Ipstenu says

      Yes, click “Google Analytics” under Web Options when you turn on PageSpeed, and you can uninstall the plugins.

      You’ll still get benefits from just having pagespeed on, and the only issue I’ve see is when you’re making a lot of CSS/JS changes, and the cache hangs on to your previous files. When that happens, you can just turn pagespeed off and then back on, and it’ll flush the cache for you.

      • Prayers and Apples says

        ok thanks! i followed your advice from the other forum post – i just changed my PHP settings to 5.3xFastCGI. I checked Pagespeed. I also installed WP Super Cache and clicked “Compress files so they’re served more quickly” and “Use PHP to serve cache files.” How long do you think it will take for me to notice a difference in page speed? Is there anything else I should do? And last question (thanks for your patience!): should I uninstall my Widget Cache plugin or will it just work with WP Super Cache?

      • Prayers and Apples says

        One more: do I have to sign up for Google Apps? I’m getting a message on my screen that’s saying it’s important that I do – but it’s not a free service. What happens if I don’t (and will this affect my page speed)?

  2. says

    I’m using PHP 5.2.xFastCGI, to change the PHP mode to PHP 5.3.xFastCGI(default) i just select it in dropdown menu? No harm will be done? And then I select Page Speed Optimization and that’s it, no?

    • Ipstenu says

      And click ‘save’ yes :) No harm done. If you don’t like it, or it doesn’t work, you can click it back.

      I don’t know of anything that doesn’t work on 5.3 now, which is pretty solid in so far as PHP goes.

  3. says

    # BEGIN WordPress
    <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>
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    
    # END WordPress
    

    Sorry i tried to post it properly but i don’t know how to…

    • Ipstenu says

      Don’t worry :) You can just use the HTML code tags most of the time.

      Yes, that’s the right way to do it. I actually tend to put it outside of WP, so i have this:

      # Begin PageSpeed
      
          ModPagespeed on
          [whatever]
      
      # END PageSpeed
      
      # BEGIN WordPress
      ....
      # END WordPress
      

      It just helps me later on when I’m trying to add new things :)

  4. says

    Hi, just wanted to say that i checked my site with PageSpeed Insights Analyzing Tool and i did somemore changes to get more speed, like this one on the .htaccess file:

    # WEEK
        Header set Cache-Control "max-age=604800, public"
    # WEEK
        Header set Cache-Control "max-age=86400"
    

    Also i checked this post to minimize wordpress queries in the theme… site is so fast now!! thanks a lot!

    • Ipstenu says

      You know… I have never used CloudFlare or any other CDN. I understand what they’re for, but I can’t really see the benefit unless I was running a massive photo heavy site.

  5. Shane says

    Do you know if this is enabled by default these days? Dreamhost placed 2/10 in my last batch of page speed tests, which is pretty impressive. Maybe they have this feature on for everyone now.

  6. says

    Abhishek Jain, DarkUFO: No, blogger does not cunrertly implement mod_pagespeed, and because it is a hosted service there is no way to enable this functionality from the client.Sunita Kumari: mod_pagespeed can be used with any website that is served by an Apache HTTP server! Check the documentation and instructions by following the link in the blog post.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>