Apache Cache Headers

Here are some nice Apache configuration entries that will increase your website performance. They can be placed in a .htaccess file:

<IfModule mod_headers.c>
  ##
  # Add a Vary Accept-Encoding header for the compressed resources. If you
  # modify the file types above, make sure to change them here accordingly.
  ##
  Header unset ETag
  #  Header set Cache-Control "no-cache" -> Cache aus
  <FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css)$">
    Header unset Last-Modified
    Header append Cache-Control "public, max-age=3600"
  </FilesMatch>
  <FilesMatch "\.(html)$">
    Header unset Last-Modified
    Header append Cache-Control "public, max-age=60"
  </FilesMatch>
  #  <FilesMatch "\.(js|css|xml|gz)$">
  #    Header append Vary Accept-Encoding
  #  </FilesMatch>
  #  <FilesMatch "\.(ttf|otf|eot|woff|svg)$">
  #    Header set Access-Control-Allow-Origin "*"
  #  </FilesMatch>
</IfModule>
 
<IfModule mod_expires.c>
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
 
    ExpiresActive On

    # Attention: This line could cause unwanted caching behavior. 
    # It's better leave it and define every contenttype you want to cache):
    ExpiresDefault "access plus 1 day"

    ExpiresByType image/x-icon                  A86400
    ExpiresByType image/png                     A86400
    ExpiresByType image/gif                     A86400
    ExpiresByType image/jpg                     A86400
    ExpiresByType image/jpeg                    A86400
    ExpiresByType text/javascript               A86400
    ExpiresByType text/x-js                     A86400
    ExpiresByType application/x-javascript      A86400
    ExpiresByType application/javascript        A86400
    ExpiresByType text/css                      A86400
    ExpiresByType audio/mpeg                    A86400
 
 
    # Add correct content-type for fonts
    AddType application/vnd.ms-fontobject       .eot
    AddType font/ttf                            .ttf
    AddType font/otf                            .otf
    AddType font/x-woff                         .woff
    AddType image/svg+xml                       .svg
    AddType video/ogg                           .ogv
    AddType audio/ogg                           .ogg
 
    # Add a far future Expires header for fonts
    ExpiresByType application/vnd.ms-fontobject     "access plus 1 day"
    ExpiresByType font/ttf                          "access plus 1 day"
    ExpiresByType font/otf                          "access plus 1 day"
    ExpiresByType font/x-woff                       "access plus 1 day"
    ExpiresByType image/svg+xml                     "access plus 1 day"
    ExpiresByType video/ogg                         "access plus 1 day"
    ExpiresByType video/ogg                         "access plus 1 day"
    # ^ All static resources will be cached in the client-browser and proxies for 1 day
 
</IfModule>
FileETag none

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.