Mod expires
official doc: http://httpd.apache.org/docs/current/en/mod/mod_expires.html
Introduction
This module controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server responses. The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access.
These HTTP headers are an instruction to the client about the document's validity and persistence. If cached, the document may be fetched from the cache rather than from the source until this time has passed. After that, the cache copy is considered "expired" and invalid, and a new copy must be obtained from the source.
To modify Cache-Control directives other than max-age (see RFC 2616 section 14.9), you can use the Header directive.
When the Expires header is already part of the response generated by the server, for example when generated by a CGI script or proxied from an origin server, this module does not change or add an Expires or Cache-Control header.
Syntax
The ExpiresDefault and ExpiresByType directives can also be defined in a more readable syntax of the form:
ExpiresDefault "base[plus num type] [num type] ..." ExpiresByType type/encoding "base[plus num type] [num type] ..."
where base is one of:
- access
- now (equivalent to 'access')
- modification
The plus keyword is optional. num should be an integer value, and type is one of:
- years
- months
- weeks
- days
- hours
- minutes
- seconds
For example, any of the following directives can be used to make documents expire 1 month after being accessed, by default:
ExpiresDefault "access plus 1 month" ExpiresDefault "access plus 4 weeks" ExpiresDefault "access plus 30 days"
The expiry time can be fine-tuned by adding several 'num type' clauses:
ExpiresByType text/html "access plus 1 month 15 days 2 hours" ExpiresByType image/gif "modification plus 5 hours 3 minutes"
Note that if you use a modification date based setting, the Expires header will not be added to content that does not come from a file on disk. This is due to the fact that there is no modification time for such content.
Common Configuration
.htacess
<IfModule mod_expires.c> ExpiresActive On #Images ExpiresByType image/jpg "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/gif "access plus 1 year" ExpiresByType image/png "access plus 1 year" AddType image/x-icon .ico ExpiresByType image/ico "access plus 1 year" ExpiresByType image/icon "access plus 1 year" ExpiresByType image/x-icon "access plus 1 year" #Elements ExpiresByType application/xhtml+xml "access plus 1 week" ExpiresByType text/html "access plus 1 week" ExpiresByType text/css "access plus 1 week" ExpiresByType application/javascript "access plus 1 week" ExpiresByType text/x-javascript "access plus 1 week" #Others ExpiresDefault "access plus 1 month" </IfModule>