Programming Tutorials

apache increase cache to static files js and css for 1 year

By: Faizal in Apache Tutorials on 2023-04-03  

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:

  1. Open the Apache configuration file (httpd.conf) in a text editor.
  2. Locate the mod_expires module, which should be loaded by default on most installations of Apache.
  3. Add the following configuration directives to set the Expires header 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>
  1. 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






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Apache )

Latest Articles (in Apache)