Reputation: 1523
This should be straight forward but apparently not.
I am trying to avoid a service-worker file from being cached on a Apache server.
The file is sw.js
and its placed on /public_html/
, as it should.
I have tried several combinations of the <FilesMatch ??? >
below, like "sw\.js$"
without success.
<FilesMatch "^(sw\.js)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 08 Jan 1975 05:00:00 GMT"
</ifModule>
</FilesMatch>
According to this ,if I run
`curl -I -L https://www.soeezauto.com/sw.js | grep cache-control`
I should receive a cache-control: no-cache
, but I do not.
Upvotes: 2
Views: 144
Reputation: 785146
Your regex inside FilesMatch
directive appears correct. However do note that Apache will send following header in response:
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Notice mixed case header name here Cache-Control
.
Your grep
command is searching for all lowercase header name i.e. cache-control
, hence no output is showing.
You need to use -i
(ignore case) matching in grep
or search for exact same header i.e. Cache-Control
.
So any of the following grep
will work:
grep -i 'cache-control'
or
grep 'Cache-Control'
For better efficiency add -F
option for fixed string search since you're not using any regex in grep
pattern to make it:
grep -iF 'cache-control'
Upvotes: 2