Website Cache Control Using Apache 2.x and mod_expires

mod_expires – This module controls the setting of the Expires 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.

The Expires HTTP header is 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.

mod_expires is included in most default installs.

Check wheter LoadModule expires_module modules/ is enabled or not in httpd.conf, if its not then uncomment it removing the # prefix.

And then add following code into your httpd.conf configuration file –

<IfModule mod_expires.c>
 # enable expirations
 ExpiresActive on
 # expire images after a month in the client's cache
 ExpiresByType image/jpg "access plus 60 days"
 ExpiresByType image/png "access plus 60 days"
 ExpiresByType image/gif "access plus 60 days"
 ExpiresByType image/jpeg "access plus 60 days"
 # css may change sometimes
 ExpiresByType text/css "access plus 1 days"# special MIME type for icons
 ExpiresByType image/x-icon "access plus 360 days"

Restart apache server.

Resource links –

Related Posts:

3 Responses

Polprav October 14, 2009 at 11:42 am

Hello from Russia!
Can I quote a post in your blog with the link to you?

Excellent. Thanks so much for the post. -Kate October 14, 2009 at 11:42 am

Excellent. Thanks so much for the post. -Kate

abstract art October 14, 2009 at 11:42 am

I enjoyed checking out your blog today and I will be back to check it more in the future so please keep up your good quality work. I love the colors that you chose, you are quite talented!

Comments are closed.