Leverage Browser Caching by htaccess

Browser caching stores webpage resource files on a local computer when a user visits a webpage.When a web browser displays webpage it has to load several things like images, css file, and other resources.

Advantage of Browser Caching

What browser caching does is “remember” the resources that the browser has already loaded. When a visitor goes to another page on your website your images, CSS files, etc. do not need to be loaded again, because the browser has “remembered” (saved) those files. This is the reason that the first view of a web page takes longer than repeat visits.

When we leverage browser caching, our webpage resource files will get stored in the browser cache. So the web pages will load much faster for repeat visitors as it doesn’t load the resources which has already saved in browser cache and share the same resources for other web pages.

htaccess Leverage Caching

Add the following code to .htaccess file.

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 text/html "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 1 month"


Leave a Reply