1

This is the HTTP header I typically use to ensure that an image is not cached. And the reason why I do this to a select few images is because I have an image application integrated in my site and caching the images would make the application broken.

I use the following:

cache-control: no-cache,no-store,must-revalidate

I tested in Opera 11.6 and Firefox 17.0.1. Opera 11.6 works fine, however Firefox 17.0.1 decides to cache the image anyways until I force-reload the page, and this is even after I choose to clear all caches and cookies in that browser.

I remember there is a pragma: no-cache back in the day, but at the rate that technology is advancing, I wonder if that line is still effective today.

Can I somehow tweak cache-control to make firefox behave, or will I need to include pragma as well? And I'm looking for a solution so that all browsers can understand that no caching means no caching.

  • could you try this: <FilesMatch "\.(jpg|jpeg|png|gif|swf)$"> Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate" </FilesMatch> this never caches based on file type. – Abu Nooh Feb 21 '16 at 21:45
  • Is this also an issue in more recent versions of Firefox? – MrWhite Feb 22 '16 at 9:11
1

Here's my entire htaccess from a site, works well on various browsers though didn't test it extensively however it satisfies pagespeed ;-)

You'd just have to edit the parts necessary for you and put in file types for the time spans.

And perhaps it is more than you require but based on the last part of your question:

but at the rate that technology is advancing....

Thought it may be useful for you and others.

# 1 YEAR
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>

# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

# 1 week
<FilesMatch "\.(txt|xml|js|css)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>

# NEVER CACHE
<FilesMatch "\.(html|htm|php|cgi|pl)$">
Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
</FilesMatch>

SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css 
text/plain text/xml text/javascript application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
Header append Vary User-Agent env=!dont-vary 

Here's where parts of this came from. askapache.

| improve this answer | |
  • seems redundant to add private and max-age=0 when the other options are added, but I'll try it and see what happens – Mike -- No longer here Feb 21 '16 at 22:57
  • ...Sadly, the idea of adding those two options made no difference. I still had to refresh firefox to get the page to work properly. – Mike -- No longer here Feb 22 '16 at 2:53
  • Which version ff are you using? – Abu Nooh Feb 22 '16 at 11:16
  • I use version 17.0.1 – Mike -- No longer here Feb 23 '16 at 0:18
  • Seems to be ok on my ff 44.0.2. Just wondering if you have additional caching such as memcache/apc wp-cache etc. – Abu Nooh Feb 24 '16 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.