Leverage browser caching via .htaccess for Apache / LiteSpeed webserver
When a web page is rendered in the browser, it downloads all assets including js files, images etc on the local computer. Most of the static resources are reused for different pages of the website. For example, a banner image might be used for all pages or the same CSS page might be called for different categories.
Add the below code to the top of the .htaccess file created at the document root of the website.
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 application/x-shockwave-flash “access 1 month”
ExpiresByType image/x-icon “access 1 year”
ExpiresDefault “access 2 days”
## EXPIRES CACHING ##
Once the above code is pasted, the main static contents such as images, CSS, PDF’s, JS, etc will be kept in the browsers local cache for the time specified which helps increase page load speed and saves bandwidth too.