Enable Mod_Expires On Your Website To Cache Your Files For Speed

Mod_Expires is a module of Apache Web server which is installed by default on all of SANGKRIT.net Linux based hosting options and supports all mod_expires functionality.

It works by manipulating the expire headers returned from the hosting server, letting you control how long a client’s Web browser cache the resources. You want to tune the duration of your caching to optimize performance while still considering how often you update the resource.

When the expires header is already part of the response generated by the server, this module does not change or add an Expires or Cache-Control header—for example, when generated by a CGI script or proxied from an origin server.

How To Enable Mod_Expires?

Mod_Expires is not enabled at the global level so you will need to enable it in your .htaccess file which is present in your website’s root directory, sometimes hidden and can be viewed by changing the view option from the top right corner of cPanel’s file manager. You can enable it on a per-directory basis and it applies recursively.

SANGKRIT.net’s environment uses the vendor-provided code from Apache for mod_expires. Current Apache HTTPD documentation is accurate for using .htaccess files with SANGKRIT.net’s hosting accounts.

For instance: Given example enables mod_expires for a set of common image types and CSS files:

# Activate mod_expires for this directory
ExpiresActive on

# locally cache common image types for 7 days
ExpiresByType image/jpg “access plus 7 days”
ExpiresByType image/jpeg “access plus 7 days”
ExpiresByType image/gif “access plus 7 days”
ExpiresByType image/png “access plus 7 days”

# cache CSS files for 24 hours
ExpiresByType text/css “access plus 24 hours”

For more information, head over to Apache’s mod_expires documentation and on AskApache site that also includes some cheat sheets and examples of how to define different expire times for different elements on your website.

WordPress Users

WordPress users may also use some cache plugins such as WP Super Cache or W3 Total Cache to get this thing done easily from their admin area.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.