Cache control for a specific file

Asked

Viewed 73 times

4

If we want to implement a cache control for a particular file type, through the htaccess we can proceed as follows:

<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 year"
</IfModule>

But this is a solution for all files of a certain type, in the example above, for Javascript files.

Question

How to apply cache control to a specific file, for example: script.js ?

1 answer

2

Analyzing the documentation of mod_expires it seems not possible to differentiate files except by type.

Alternatives I can think of are:

  1. Use an extension other than js to the specific file and associate it to another mime type that gives the same result.
  2. Apply different expiration settings to different directories.

Example of item #2 (source):

<Directory /var/www/js/expire_fast>
  <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/javascript "access plus 60 minutes"
  </IfModule>
</Directory>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.