I am a person who is obsessed with application performance – be it web applications, desktop or mobile apps, I really get frustrated if screen refreshes take longer especially due to bulky code written by web developers and non-optimized images getting included in web pages.
When it comes to tuning my blogs or websites for performance (even when I was on shared hosting), I make sure that I save as many bytes as possible – especially on the home page – by optimizing images, going for a lean theme, avoiding heavy CSS/JS files and removing all unwanted comments, longer variable names etc. And Google Page Speed only made me more paranoid about those unwanted bytes.
How to Optimize with PageSpeed?
Well, I am not going to explain every single step here because almost every suggestion given by the Google PageSpeed plugin for Firefox pretty much self explanatory. However, I could give you some tips on what I am doing with this plugin as onetime optimization as well as on a regular basis (i.e. when time permits). Let’s start with the installation and Page speed execution part.
- First, if you don’t have the firebug addon yet, install it to Firefox using this link
- On top of Firebug, install PageSpeed. Alternatively, you can run pagespeed online version for page load analysis which uses the same performance rules. However, it wouldn’t be as flexibility and optimization options as in the Firefox addon version
- Now after restarting the Firefox, load your website to be analyzed, press F12 to bring up Firebug, Go to the ‘Page Speed’ tab and click ‘Analyze Performance’
- After a few seconds, your page speed score will appear giving a lot of suggestions in Red, Orange and Green
How this blog achieved a Page Speed score of 95?
Basically all that you have to do is to work with the red, orange and green items (with say less than 90% score) and take the necessary steps to boost your site performance.
Typical red items, include the following:
1. Leverage browser caching
# BEGIN CACHING
# Turn on Expires and set default to 0
# 1 YEAR
Header set Cache-Control "max-age=29030400"
(Remember to add a convenient value in seconds for max-age)
Similarly my CSS and JS files have a higher expiry value specified and this took out the red from my Browser Caching speed results
2. Enable compression
GZIP compression (or mod_deflate ) is not always possible with shared hosting services. If you have a VPS or dedicated hosting you can opt for mod_deflate configuration. In my case, I didn’t do it at the server side firstly because I didn’t know how to do it and secondly I didn’t try hard to do it because compression increases the server load.
Instead, I decided to do it at my CDN set up and looks like it’s working fine as well. I got a good score for the ‘Enable Compression’ section.
By the way, if you are interested in mod_deflate implementation on apache, this link might help
3. Optimize images
This is where there is huge potential. Basically after running, page speed will provide a detailed report on non-optimized images and even an optimized version of each image that you can view and save as the old filename (and upload to the server). This will instantly save you a lot of band width without having any image editing tool.
This ‘save as’ trick can be used to optimize individual post images as well. You may keep a backup of the original image, just in case things go wrong
- Never remove comments from your main style.css. If you are on WordPress your theme will never get recognized after that and you won’t be able to access most of theme related admin functionality. (such as editing)
- Never remove unused CSS as suggested by Page Speed. This is because, when you run the page speed analysis on your home page, some CSS may be redundant but they may be used in other pages
5. Other performance improvements
With the above steps taken care of, you should be already in lat 80s with respect to page speed score. Next you can work on the green items such as specifying image sizes, reducing number of images, combining images (image sprites which I have done on the homepage), consolidating scripts, reducing number of requests etc.
Feel free to use help on each result set by clicking the same. Also, when you hover the icons (left most) on the page speed result, you get to see the score for each ruleset and you have to correct any item with a low score.
I still have some more work to be done but at 95 out of 100, things look pretty good and sometimes the homepage is loading under 1 second.
Hope this post was useful to you. Feel free to contact me for any queries related to Page Speed and performance optimization. Couple of other things that might help you with performance is to make sure that you have clean HTML by using the HTML validator service and use a real light weight theme like the one I am using.