We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.

Your Digital Commerce Experts
Nexcess Logo

Setting Expire Headers & ETags

March 24, 2020

At Nexcess we’re all about speed & performance. One way to improve site load times is to set site assets, such as images, CSS & Javascript files, to be cached in the browser. You can do this by adding expires headers into the sites .htaccess file.

First you will need to have SSH/sFTP credentials for your site. Then with the SSH/sFTP credentials you can now edit the sites .htaccess file. Recommended settings for adding expires headers to your sites .htaccess file are shown below.

<IfModule mod_expires.c>
  ExpiresActive On


  # Images
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"


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


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


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

You can adjust the access time frame as needed for your sites needs in the .htaccess code. For example if you wanted site images and video assets to only be cached for a month.

 # Images
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType image/webp "access plus 1 month"
  ExpiresByType image/svg+xml "access plus 1 month"
  ExpiresByType image/x-icon "access plus 1 month"


  # Video
  ExpiresByType video/mp4 "access plus 1 month"
  ExpiresByType video/webm "access plus 1 month"
  ExpiresByType video/ogg "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"


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

You can also set types to be invalidated, meaning they’re no longer cached, by using Entity tags (ETags).

FileETag MTime Size
<ifmodule mod_expires.c>
  <filesmatch ".(jpg|gif|png|css|js)$">
       ExpiresActive on
       ExpiresDefault "access plus 1 year"
   </filesmatch>
</ifmodule>

Making these changes on your site will improve load times for repeat visitors and reduce the load off of your server which helps all visitors.

Patrick Rauland