Shared Hosting > Leverage Browser Caching

We all know that faster websites are better websites. Not necessarily better quality, as the Internet is full of drivel, but Google and Bing love fast websites. If you can serve fast content, they’ve openly admitted you’ll do better in their search rankings. Better ranking means more readers/subscribers/buyers/moneys. It’s meant an improvement for this WordPress blog of mine. One of the main things that slows down web pages being served, is sending the user the same data every time they visit a page. This is where Leverage Browser Caching comes into play.

Leverage Browser Caching explained

Reading that paragraph above, you may say to yourself that every page you serve your readers contains different content. Different articles, or products, or pictures of cats doing daft things. The fact is though, your content usually makes up only a small portion of the data transferred.

The largest amount of data sent is usually for images and definitely chunky video files. Cascading style sheets (CSS) and Javascript code comes a close second in chunkiness.

When the visitor goes from one page to another, your nice consistently styled website means your header images, footer code and common pictures are asked for each page view. This is where Browser Caching comes in!

Browser Caching basically means the servers tells your users’ browser –

If you’ve already got this image, it wont have changed in the last week, so don’t bother asking me for it again

If you multiply this for several large images, style sheets and Javascript files; you’ll be saving yourself a large amount of data transfered…

Less data to transfer = faster site,

Faster site = Happier search engines

Happier search engines = Happier you!

(You can read more about improving your sites speed here)

How to easily leverage browser caching

Thankfully implementing browser caching can be easy, even for shared hosting. My shared hosting is with Heart Internet, and they thankfully have recently (within the last 6months I think) added the mod_expires module to Apache.

If your hosting doesn’t have mod_expires enabled by default, drop them a support ticket and they should add it for you (fingers crossed).

What you need to do is open your .htaccess file in your root directory. If you don’t have one, simply add it making sure you add the full-stop before the file name.

Add the following:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType text/javascript "access 1 week"
ExpiresByType application/pdf "access 1 year"
ExpiresDefault "access 7 days"
</IfModule>

Save that htaccess file and thats it!

To test whether its worked, enter your website in this Google PageSpeed Insight tool and you should see a green tick beside the Leverage Browser Caching.

This should pull your load times right down which is excellent for nothing less than 10 minutes work. Let me know how much your times change, it’ll be good to the improvements.

1 thought on “Shared Hosting > Leverage Browser Caching

  1. About as straightforward as it gets, eh?

    I’ve been looking for something like this for one of my top list sites as it drains my bandwidth, although the majority don’t read the same post twice? Still worth throwing into the mix I suppose.

    Cheers Paul.

Leave a Reply

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