Skip to content
Home » Web » Apache » How to Enable Client-Side Browser Cache on Apache Web Server

How to Enable Client-Side Browser Cache on Apache Web Server

Enabling client-side browsers to cache the web pages can speed up the response time of your visitors.

According to Apache HTTP server 2.2 Module mod_expires, you can add file expiration to httpd configuration.

[root@localhost ~]# vi /etc/httpd/conf/httpd.conf
...
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 second"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType application/x-icon "access plus 1 year"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType text/html "access plus 10 minutes"
    ExpiresByType text/javascript "access plus 1 week"
</IfModule>

Please note that:

  1. Time units can be singular or plural, it depends on your cardinal numbers. For example:
  2. 1 second -> 10 seconds
    1 minute -> 30 minutes
    1 week -> 4 weeks
  3. Although text/javascript is an obsolete MIME type and is discouraged to use in favor of application/javascript, you have to add it to the list to make your Javascript files effective. 

For applying more MIME types in your web server, you may refer to this page: Internet media type

Deflating files before responding to your clients can also be helpful to the server performance, you may refer to my post as following: How to Enable Deflation of Files on Apache Web Server.

Leave a Reply

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