Speed Up WordPress With Browser Caching

How to Speed Up WordPress With Browser Caching

in Optimization & Best Practice
Google+ LinkedIn

Browser caching can help to reduce server load by reducing the number of requests per page. By setting the correct file headers on static files that don’t change (like Images, CSS, JavaScript etc) browsers will then cache these files on the user’s computer. This technique allows the browser to check to see if files have changed, instead of simply requesting them from server.

By using this code snippet in your .htaccess file, your static files will be cached for much longer time and produce faster loading of website/webpages, since browser do not need to request and download then again.

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

Share the love

If you like this snippet, share it with others!

Leave a Reply

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