How To Leverage Browser Caching For Your Blog And Website Using Htaccess

Bloggers and Webmaster always want their blog/website to load as fast as possible so that reader and visitors don’t have to wait for anything. So one of the easy ways to make your blog load faster is web browser caching, you can keep of a copy of your static files (e.g.: images, JavaScript, CSS, etc.) in your readers/visitors web browser (in other terms it is also known as “Leverage browser caching”).

Which will help you many ways, it reduces number of HTTP request, now less HTTP request means lesser loading time, lesser loading time means improving website performance,  which also let you improve your Google Page Speed and YSlow scores.

Test Your Website Speed

So if you want to leverage browser caching then simply add the below lines at the end of your htaccess file, which you will able to find in root directory of your blog or website.

#BEGIN Expires Caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType text/css A2592000
ExpiresByType text/x-javascript A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType application/pdf A2592000
ExpiresByType application/x-shockwave-flash A2592000
ExpiresDefault A2592000
#END Expires Caching

By using the above code you will able to extend expire time for images, CSS, JavaScript, PDF and SWF (flash) files. By default I have set expiry time for 30 days (2592000 seconds). You can change your expiry time to whatever you like, just make sure it is in seconds and add “A” before it.

In reply to Harsh