December 12, 2011

Caching with .htaccess

Caching with .htaccess


# Set the cache-control max-age
# For 1 year
<FilesMatch “\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$”>
Header set Cache-Control “max-age=31449600, public”
</FilesMatch>

# For 2 DAYS
<FilesMatch “\.(xml|txt)$”>
Header set Cache-Control “max-age=172800, public, must-revalidate”
</FilesMatch>

# For 4 HOURS
<FilesMatch “\.(html|htm|php)$”>
Header set Cache-Control “max-age=14400, must-revalidate”
</FilesMatch>

Followings things should be considered as well:

  • https://developers.google.com/speed/docs/insights/EnableCompression
Last updated: July 1, 2015