Google’s Page Speed has been around for a while now – if you’re not familiar with it, it’s Google online tool to show you the performance of your website. Why is this important? Well for a some time Google have been telling us that one of the things that it takes into consideration for search rankings is the speed at which the site is delivered.
So you enter your site and it gives you a rank out of 100 then provides (a usually extensive) list of things that you could do to improve your site.
I’ve been maintaining for a while a post over here where I list some useful settings for WordPress when setting up an .htaccess file. So refer to that as well but commonly what Page Speed suggests is that you should enable Browser Caching. What this does in effect is tell a visitor’s browser that they should store the content (think images, CSS files etc.. ) in their local browser cache instead of always attaching to the web server to download the content.
How to do it?
Well this is for unix and linux style web servers, if you use windows / IIS this will not work for you.
Firstly setup the caching with this kind of thing in your .htaccess file at the root of your web site.
This will turn on browser caching by default and set the default to one month (A2592000 more on that in a moment) then allows you to specify different time frames for different kinds of media. “ExpiresByType image/png A2592000” for example is specifically for png images.
If you’re reading this because you’re tried this kind of thing and it did not work it may be because of the particular server you’re on. Most of the work that I do is hosted on Rackspace’s Cloud Sites, where the above syntax does work. A lot of examples that I found around the web were in this format.
ExpiresByType image/jpg “access 1 year”
Which for some reason did not work. So try one way or the other, ideally both should work but if the A2592000 way of describing a month does not work then try “access 1 month”.
What is A2592000 anyway?
A in A2592000 stands for Access and will set the expires for 2592000 seconds which is 1 month after the user has accessed the file. M is for Modified. M2592000 would mean set expire date to one month after the file has been modified.
So get your calculator out and work out how many seconds are in a day, month, year etc.. to work out how to configure it.
Still doesn’t work?
So again in a lot of the examples you’ll find around the web it tells you to place this kind of code in your .htaccess but if it still does not work then look at your mime types.
I’ve found this on more than one web environment, by default jpg images for example are not served with the correct mime type, instead turning up in the brewer with mime type being “undefined”
What you’re doing with the above mentioned browser caching set it basically saying for mime type images/jpg cache for 1 month. If your jpg images are not being served with the correct mime type the setup won’t work.
Again though, there is an easy solution. Set the mime type in .htaccess, what you’re doing here is saying if the file extension is .jpg then serve it with the correct mime type for that.
Put this code into your .htaccess to active this.
AddType image/gif .gif AddType image/jpeg .jpg AddType image/png .png AddType image/svg+xml .svg AddType image/svg+xml .svgz
Then back to Google Page Speed and you should find that you’ve got a better score!