How to Leverage Browser Caching for Images, CSS and JavaScript?

HostStud

Administrator
Staff member
You can keep following code in your .htaccess file specifying how long the web browsers should keep images, videos, pdf, flash, CSS and JS in visitors PC or Laptop.
This way the visitors's browser will keeps the most of the data, which will improve the speed of your website.

<IfModule mod_expires.c>
ExpiresActive On

# Images
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"

# CSS, JavaScript
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"

# Video
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/mpeg "access plus 1 month"

# Others
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"

</IfModule>
 
Last edited:
Top