开发者

Enabling mod_expire depending on request

Instead of generating links to file.js, I'm calculating a version number or hash sum and linking to file--bbe02f946d.js. I'm using the following redirect rule to then serve the current version of the file:开发者_JAVA技巧

RewriteRule ^(.*)--[a-z0-9]+\.js$ $1.js

Now, I want to set extremely far away Expires headers for those requests:

ExpiresActive on
ExpiresByType application/javascript "access plus 1 year"

This works fine, but applies to not yet versioned resources (/file.js requests) too. How can I set the expires headers only for the requests matching the RewriteRule? Normally, I'd use <LocationMatch>, but that's not available since the application must be able to run on arbitrary servers where I can just modify htaccess.


You could add a new mime type with htaccess and set custom expire headers.

Example using .xjs

<IfModule mod_mime.c>
    AddType application/x-javascript .xjs
</IfModule>

<IfModule mod_gzip.c>
mod_gzip_item_include file \.xjs$
</IfModule>

<FilesMatch ".(xjs)$">
Header set Cache-Control "max-age=43200"
</FilesMatch>

or just use regex in FilesMatch to match your js file

<FilesMatch "--[a-z0-9]+\.js$">
Header set Cache-Control "max-age=43200"
</FilesMatch>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜