1252748
1252748

Reputation: 15372

not cache image linked in stylesheet

when I am debugging to ensure that some files are not cached and therefore reloaded anew each time, I frequently link files with something like

<script src="script/js.js?<?=time()?>"></script>

Is there some way I can do something in css to ensure background images are reloaded every time the page loads without making the style something other than a .css file? (php with css header for example)

#bg_div{
background: url(../images/darrow.png.....)
}

Thanks!

Upvotes: 1

Views: 68

Answers (1)

jtheman
jtheman

Reputation: 7491

You could use .htaccess like this:

<filesMatch "\.(gif|jpg|png)$">
 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 "Mon, 26 Jul 1990 05:00:00 GMT"
 </ifModule>
</filesMatch>

This prevents all images to be cached. If you put the .htaccess file in a specific folder then images in this folder doesn't get cached.

Note that on sites with heavy load cache control should be carefully planned. Using a htaccess directive like this can VASTLY affect page load times.

Upvotes: 1

Related Questions