Cache control for a specific file

4

If we want to implement a cache control for a particular file type, using 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 ?

    
asked by anonymous 11.11.2014 / 16:56

1 answer

2

Looking at the mod_expires documentation it seems that it is not possible to differentiate files other than by type.

Alternatives I can think of are:

  • Use an extension other than js for the specific file and associate it with another mime type that gives the same result.
  • 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>
    
        
    11.11.2014 / 17:22