Eevee

Adding Expires Header To Website Content

Apache

A way for Apache servers to add the Expires header:

Edit the .htaccess file and add the following to tell the browser what types of files to cache.

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"

Nginx

The Nginx server’s method of adding the Expires header: Add the following to your website’s configuration file and restart the nginx service.

location ~* \.(jpg'jpeg'png'gif'ico'css'js)$ {
        expires 365d; 
    }location ~* \.(pdf)$ {
        expires 30d;
}