Leverage Browser Caching with .htaccess

I was working on a WordPress site But whenever I ran PageSpeed test on the site, it keeps giving me red lights to ‘Leverage Browser Caching’ and ‘Enable Compression’, forget PageSpeed of Google if you go to www.gtmetrix.com and check your speed you will see red line of having low or no Leverage Browser Caching.I tried many Cache Plugins such as WP CACHE, HYPER CACHE etc Now i am going to show you how to fix this issue through .htaccess, its pretty simple just copy the code below and paste into you htaccess file and see the difference.
[code]

## 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 ##

[/code]

Enabling Compression with .htaccess

If you dont know what Gzip Compression is you can go to this article https://developers.google.com/speed/articles/gzip and learn about it,its pretty useful technique to speedup websites,With following code on htaccess file, we’ll be enabling Gzip compression on the server. It’ll reduce the size of HTTP response. Almost all web browsers claim to support it. Add following code at the end of .htaccess file to enable compression.
[code]

## BEGIN GZIP ##

    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript

    ## END GZIP ##

[/code]
Finally clear all cache and run the Google PageSpeed test or www.gtmetrix.com again. You should see green lights for Leverage Browser Caching and Enable Compression.

1 Comment

  1. Great Advice, i implemented the changes in my htaccess file and ran the test on gtmetrix and my site had moved up a grade 🙂

Comments are closed.