Htaccess Cache Specifics files

Using Htaccess file you can speed up the loading time of your site with Header and ETag.

Example

Header unset ETag
FileETag None

# 21 DEC 2012
<filesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css)$">
Header unset Last-Modified
Header set Expires "Fri, 21 Dec 2012 00:00:00 GMT"
Header set Cache-Control "public, no-transform"
</filesMatch>

# 3 HOUR
<filesMatch "\.(txt|xml|js|css)$">
Header set Cache-Control "max-age=10800"
</filesMatch>
 
# NEVER CACHE
<filesMatch "\.(html|htm|php|cgi|pl)$">
Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
</filesMatch>

Explanations

  • remove and disable the ETag is because supposedly some browsers will ignore your Expires header when it’s present:
    Header unset ETag
    FileETag None
  • remove the Last-Modified header is because supposedly some browsers will ignore it:
    Header unset Last-Modified
  • set the Cache-Control header to ‘public’ is so the browser will cache media over HTTPS:
    Header set Cache-Control "public, no-transform"
  • set the Cache-Control header to ‘no-transform’ is to prevent proxies from modifying my content:
    Header set Cache-Control "public, no-transform"

Time Cheatsheet

#      300   5 MIN
#      600  10 MIN
#      900  15 MIN
#     1800  30 MIN
#     2700  45 MIN
#     3600   1 HR
#     7200   2 HR
#    10800   3 HR
#    14400   4 HR
#    18000   5 HR
#    36000  10 HR
#    39600  11 HR
#    43200  12 HR
#    46800  13 HR
#    50400  14 HR
#    54000  15 HR
#    86400   1 DAY
#   172800   2 DAY
#   259200   3 DAY
#   345600   4 DAY
#   432000   5 DAY
#   518400   6 DAY
#   604800   1 WEEK
#  1209600   2 WEEK
#  1814400   3 WEEK
#  2419200   4 WEEK
#  4838400   2 MONTH
#  7257600   3 MONTH
#  9676800   4 MONTH
# 12096000   5 MONTH
# 14515200   6 MONTH
# 16934400   7 MONTH
# 19353600   8 MONTH
# 21772800   9 MONTH
# 24192000  10 MONTH
# 26611200  11 MONTH
# 29030400  12 MONTH

Random posts