Add Expires headers to your website

Add Expires Headers

Web pages are becoming increasingly complex with more scripts, style sheets, images and even clips or audio on them. A first-time visit to a page may require several HTTP requests to load all the components. By using Expires headers these components become cacheable, which avoids unnecessary HTTP requests on subsequent page views. Expires headers are most often associated with images, but they can and should be used on all page components including scripts, style sheets and even clips.

To enable this, add bellow the last line your website .htaccess file the following string. Costumize the periods depending on your website content update strategy.

<IfModule mod_expires.c>
  ExpiresActive on

# Your document html
  ExpiresByType text/html "access plus 60 seconds"

# Media: images, video, audio
  ExpiresByType audio/ogg "access plus 1 week"
  ExpiresByType image/gif "access plus 1 week"
  ExpiresByType image/jpeg "access plus 1 week"
  ExpiresByType image/jpg "access plus 1 week"
  ExpiresByType image/png "access plus 1 week"
  ExpiresByType video/mp4 "access plus 1 week"
  ExpiresByType video/ogg "access plus 1 week"
  ExpiresByType video/webm "access plus 1 week"

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