This article is an introduction to Apache's document expiration functionality provided by the mod_expires module.
Setting expiration periods for web content enables web browsers to cache content for specific periods of time. As a result, you can reduce the number of HTTP requests that the web server must process, which helps improves web site speed and performance.
Apache's mod_expires module enables you to define expiration intervals for different types of content on your web site. For example, you could use mod_expires directives to instruct browsers to cache image files for one hour, JavaScript files for two weeks, and CSS files for two months.
The following sample .htaccess configuration demonstrates how to do this:
<IfModule mod_expires.c> ExpiresActive On ExpiresByType image/png "access 1 hour" ExpiresByType image/gif "access 1 hour" ExpiresByType image/jpeg "access 1 hour" ExpiresByType text/javascript "access 2 weeks" ExpiresByType text/css "access 2 months" ExpiresByType text/html "modification 4 hours" ExpiresDefault "access 2 days" </IfModule>
In this example:
To verify your expiration settings in the .htaccess file are working correctly, you can examine the raw HTTP headers sent between the browser and web server. (To do this, use a browser plugin that displays the raw headers such as Live HTTP headers for Mozilla Firefox, or the Developer Tools feature in Google Chrome.) When content is marked for expiration, Apache adds the following lines to the HTTP response header (the exact values will vary based on your own .htaccess settings):
Cache-Control: max-age=86400 Expires: Thu, 02 Oct 2014 19:02:30 GMT
For more information about the mod_expires module, please visit https://httpd.apache.org/docs/2.2/mod/mod_expires.html.
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.