Setting up proper caching on Apache
This technique gives a possible implementation for the CategoryBpCaching when using the Apache server.
Pre-requesites:
- The content being served is static
Apache version >= 1.2 with mod_expires available and enabled
- AND
- access to the server main configuration file (usually, httpd.conf)
- OR being allowed to use .htaccess files with overrides on Indexes allowed
Implementations Steps:
Set ExpiresActive to On with ExpiresActive On in the httpd.conf file for the relevant part of the site or set it in a .htaccess file in the directory you want this to be applied
Set a default expiry time for your content as a whole; the actual value will depend of the frequency of updates of your site and can be changed depending on directory (by applying it in a different section or in a different .htaccess file), and by content type (using ExpiresByType)
- If the change was made in the main configuration file, the Apache server needs to be restarted
Configuration sample
This shows how the W3C Apache 1.3 servers are configured to serve content by type and by location:
# Enables the use of the expires directive AddModule mod_expires.c ExpiresActive on # The W3C site is generally speaking quite often updated, so we use a 6 hours expiry by default ExpiresDefault "access plus 6 hours" # but most images are very rarely updated, so a 1 month expiry is good ExpiresByType image/gif "access plus 1 month" ExpiresByType image/svg+xml "access plus 1 month" ExpiresByType image/png "access plus 1 month" ExpiresByType image/jpeg "access plus 1 month" # The dated documents in the so called TR space are unmutable, so we set a very high expiry <Location ~ "/TR/[0-9]{4}/*"> ExpiresDefault "access plus 1 year" </Location>
Further reading