Improve Website Performance Part-1 Tricks by Rajesh Kumar Sahanee - June 6, 2017July 10, 20170 Post Views: 5,294 Hello Friends, Today I am going to share how to improve your website performance and how to reduce website load time. Today I am going to tell you about Leverage browser caching. Leverage browser caching : – Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network, which reduces load time. To do this we can specify expiry for resource in server’s .htaccess file so that resources would be loaded from local disk instead of server till expiry time. So here is the code which you can write in .htaccess file. .htaccess ## 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 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" </IfModule> ## EXPIRES CACHING ## 12345678910111213141516 ## EXPIRES CACHING ##<IfModule mod_expires.c>ExpiresActive OnExpiresByType 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"</IfModule>## EXPIRES CACHING ## In the code you can see we can define different expiry time for different type of resources. .htaccess ExpiresByType image/jpg "access 1 year" ExpiresByType image/jpeg "access 1 year" ExpiresByType image/gif "access 1 year" ExpiresByType image/png "access 1 year" 1234 ExpiresByType image/jpg "access 1 year"ExpiresByType image/jpeg "access 1 year"ExpiresByType image/gif "access 1 year"ExpiresByType image/png "access 1 year" Here these four lines of codes are for image types .htaccess ExpiresByType text/css "access 1 month" 1 ExpiresByType text/css "access 1 month" Here we are setting expiry for css files. .htaccess ExpiresByType text/html "access 1 month" ExpiresByType application/pdf "access 1 month" 12 ExpiresByType text/html "access 1 month"ExpiresByType application/pdf "access 1 month" Here we setting expiry for html and pdf files. .htaccess ExpiresByType text/x-javascript "access 1 month" 1 ExpiresByType text/x-javascript "access 1 month" Here we setting expiry for javascript files. .htaccess ExpiresByType application/x-shockwave-flash "access 1 month" ExpiresByType image/x-icon "access 1 year" 12 ExpiresByType application/x-shockwave-flash "access 1 month"ExpiresByType image/x-icon "access 1 year" Above two lines of codes are for flash files and icon images. .htaccess ExpiresDefault "access 1 month" 1 ExpiresDefault "access 1 month" This line sets expiry for all other resources. There is another method also for setting expiry in .htaccess file .htaccess # 1 Month for most static assets <filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$"> Header set Cache-Control "max-age=2592000, public" </filesMatch> 1234 # 1 Month for most static assets<filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">Header set Cache-Control "max-age=2592000, public"</filesMatch> In .htaccess file # is used for comment so the first line is ignored here. .htaccess <filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$"> 1 <filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$"> Above tells which files types to be chached. .htaccess Header set Cache-Control "max-age=2592000, public" 1 Header set Cache-Control "max-age=2592000, public" Header set Cache-Control is setting header max-age=2592000 is defining expiry or max-age of resources and public just defining it is public References https://developers.google.com/speed/docs/insights/LeverageBrowserCaching https://varvy.com/pagespeed/leverage-browser-caching.html Thanks Please share if you like