Leverage Browser Caching to Increase Website Speed

By Posted 2010 Updated   BloggingSEOTutorials

If you can leverage browser caching, you can increase website speed considerably. As Google starts considering site speed as a SEO parameter, webmasters can leverage browser caching to improve site speed and get better search engine rankings.

Why browser caching?

If you set an expiry date or a maximum age in the HTTP headers for static resources, modern browsers will load previously downloaded static resources like images, css, javascript, pdf, swf etc. from local disks rather than over the network.

So if you configure your web server to set caching headers and apply them to all cacheable static resources, your site will appear to load much faster.

How to leverage browser caching

Find your .htaccess file in the root of your domain. I edited it with Notepad to add these lines of code below and save it (not as .txt).

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

This basically enables instructs the browser to cache different static resources like images, javascript, flash, pdf, and icons for the specified period of time. You can increase or decrease the values depending on your specific requirements. The more static or unchangeable your resource, longer the period you can enable browser caching. You can read more about the Apache Module mod_expires and how generation of Expires and Cache-Control HTTP headers instruct the client about the document’s validity and persistence.

You remember our site was slower than 94% sites online and we will present a series of articles on how we are speeding up our site to get better search engine rankings and SEO.


21 comments on “Leverage Browser Caching to Increase Website Speed

  1. Redemption says:

    Hi, i’ve insert in my htaccess the code below, but, if i check with google page speed it don’t recognize the leverage browser caching in my site. Why?

    Thank you.

    • Caue says:

      Has your server the mod_expires module? If it doesn’t, the lines within IF statement are not read

  2. chris says:

    same i inserted into my htaccess and had no effect……………..

  3. Delhi Hotels says:

    I am also using windows server, Facing the same problem

  4. sariyanta says:

    same, when i deleted the
    ## EXPIRES CACHING ##

    and

    ## EXPIRES CACHING ##
    it causes an error

  5. plintu says:

    Just so everyone knows, his .htaccess method does not work save some time adn do something more simple

    ExpiresActive On
    ExpiresDefault “access plus 1 month”

  6. TheShadow says:

    Thanks for the hint.can you tell me how can i be sure that its working

  7. Jc says:

    i have set above code for css and surf the website, then i changed background in css and surf the website so the changes are coming on the website. so it means caching not worked. can you please guide me how to implement it.

  8. arslanone says:

    Hi guys

    If you look at this page http://httpd.apache.org/docs/2.0/mod/mod_expires.html it tells you the keywords are years, weeks, days, hours, minutes and seconds. Not the way the writer posted on his post.

    So I did this, and now Google Chrome PageSpeed in developer tools the red light for leverage browser cache warning is gone!

    ExpiresActive On
    ExpiresDefault “access plus 1 week”
    ExpiresByType text/css M604800

    Thanks.

  9. Jane Bowlin-Burt says:

    Awesome! I inserted mine using Notepad and the site score went up 11 points immediately! Thanks so much for making this easy!

  10. Suresh N says:

    As arslanone told, this post was not working 100% for me. After changing “access 1 year” to A2592000. It started working 100%, anyway nice post with explain.

  11. Mahesh Mohan says:

    The best way to improve the performance is by using W3 Cache or Super Cache plugin.

  12. maximum leverage says:

    Truly enjoyed the info supplied here.

  13. Hernán says:

    Thank you! It seems it worked :)

  14. Jorge says:

    The code is fine. If it doesn’t work for you, make the terms plural: i.e. weeks, months, days

  15. kuzzcor says:

    ADD THIS

    ExpiresActive On
    ExpiresDefault A600
    ExpiresByType image/x-icon A2592000
    ExpiresByType application/x-javascript A604800
    ExpiresByType text/css A604800
    ExpiresByType image/gif A2592000
    ExpiresByType image/png A2592000
    ExpiresByType image/jpeg A2592000
    ExpiresByType image/jpg A2592000
    ExpiresByType text/plain A86400
    ExpiresByType application/x-shockwave-flash A2592000
    ExpiresByType video/x-flv A2592000
    ExpiresByType application/pdf A2592000
    ExpiresByType text/html A600

  16. Aadi says:

    Finally I done it now my site is loading very fastly ..thanks bro ..

  17. Arun Basil Lal says:

    I cannot remember the number of times I have returned to this page to copy this code. Thanks for this mister!

  18. Dimas Arie Prasojo says:

    I like this article, and i have been test on my blog, score gtmetrix.com is 99 and yslow 99 for my website. this trick is very good….!!!

  19. Hansraj says:

    Page Caching
    Importance
    Easy to Solve Website does not allow page caching.
    The website is not configured to allow page caching.
    Apache:
    Add this to the .htaccess file in the website main directory.

    # Enable expirations
    ExpiresActive On
    # HTML
    ExpiresByType text/html “access plus 2 days”

    but this code is note worked

Leave a Reply

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




css.php