Leverage Browser Caching in WordPress via .htaccess
WordPress caching is the fastest way to improve performance. If your site is getting hit right now install W3 Total Cache or WP Super Cache.
In addition to use above mentioned plugins,we can also leverage browser cashing to speed up our wordpress site. And the easiest way is to use .htaccess method.
In order to do this, we will need to modify our .htaccess
file and add in the appropriate directives.
Finding and Modifying .htaccess
For those that are not tech savvy, modifying the .htaccess
file might seem a little daunting. In reality, it is quite simple. For this tutorial, if you can cut and paste correctly, you should be worry-free.
.htaccess
file through cPanel by clicking on the File Manager. When the popup box appears, click on the Web Root option and make sure that the “Show hidden files” option is checked.Pasting in the Directives to Leverage Browser Caching
Open up your .htaccess
file and paste in the following directives at the top of the file:
[text]
## EXPIRES 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>
## EXPIRES CACHING ##
[/text]
By using this code, our main static files (images, CSS, PDF’s, JS, etc.) will be cached in order to produce faster loading times in the future.
Now save your .htaccess file and view your site through the eyes of PageSpeed and YSlow! – you are now leveraging browser caching for your site!
Thanks Thomas Griffin for this tutorial