To increase the cache time for static files such as JS and CSS files served by Apache, you can modify the Expires header of the HTTP response. The Expires header specifies the date and time when the cached resource is considered to be expired.
Here's how you can configure Apache to set the Expires header to 1 year for static files:
- Open the Apache configuration file (
httpd.conf) in a text editor. - Locate the
mod_expiresmodule, which should be loaded by default on most installations of Apache. - Add the following configuration directives to set the
Expiresheader for static files:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
</IfModule>
- Save the configuration file and restart Apache to apply the changes.
These directives tell Apache to set the Expires header for CSS and JavaScript files to 1 year from the time the file is accessed. This will instruct browsers and other clients to cache the files for a year, reducing the number of HTTP requests and improving performance