The Browser doesn't refresh cached files until the given Expires header expired. If it's expired, it will request the file with an If-None-Match header (I guess).
Up vote 1 down vote favorite 1 share g+ share fb share tw.
Im having trouble with caching... Im using this php file with url rewriting to compress and cache css and js I was under the impression that if I changed/updated one of my files, that the browser would retrieve the updated file. But it doesn't unless I clear the cache or refresh the page. Is my coding wrong?
Or is the browser not suppose to get updated content until the cache expiration period has expired? Rewrite rules RewriteRule ^(.*). Js$ /compress.
Php? File=$1. Js&type=js L,QSA RewriteRule ^(.*).
Css$ /compress. Php? File=$1.
Css&type=css L,QSA RewriteRule ^(.*). Ico$ /compress. Php?
File=$1. Ico&type=ico L,QSA --------- EDIT: Maybe I should be doing this a different way? What do the big companys use to cache, and how do they force browsers to get the updated content before the cache is set to expire?
EDIT 2: Thanks guy for the help. Im going with a 1 hour cache php caching etag link|improve this question edited Aug 4 '11 at 17:41 asked Aug 3 '11 at 20:25tuurbo506 33% accept rate.
The Browser doesn't refresh cached files until the given Expires header expired. If it's expired, it will request the file with an If-None-Match header (I guess). But why didn't you handle cache control via .
Htaccess? You could check mod_expires: # Expires-Header ExpiresActive On ExpiresByType application/javascript "access plus 7 days" ExpiresByType text/css "access plus 7 days" # ETag FileETag All Gzip compression as well with mod_deflate: AddOutputFilterByType DEFLATE text/css application/javascript Edit: 'Big companies' don't use Expires or max-age headers, or they will set these headers to let cache files for ~1 hour -> conflicts with caching will be minimized. You're setting it to 1 week.
Im using II7 and a url rewrite from helicontech – tuurbo Aug 3 '11 at 21:00 I edited my post to answer your edit. – Floern Aug 3 '11 at 21:47.
You missing these part, I believe... $last_modified = filemtime($file); // Check for cached version if(isset($_SERVER'HTTP_IF_MODIFIED_SINCE') OR isset($_SERVER'HTTP_IF_NONE_MATCH')) { // these part should do that... if ($_SERVER'HTTP_IF_MODIFIED_SINCE' == gmdate('D, d M Y H:i:s \G\M\T', $last_modified)) { header('HTTP/1.0 304 Not Modified'); return; } } header('Last-Modified : '. Gmdate('D, d M Y H:i:s \G\M\T', $last_modified)); header('Cache-Control : max-age='. $expires.
', must-revalidate'); header('Expires : '. Gmdate('D, d M Y H:i:s \G\M\T', $last_modified + $expires)); // and so on... btw, for helping you determine, much more, related how your cache performance, or even better, your whole app performace, you can test it by using Google API performance, or these sites : http://www.webpagetest.org/ (PS: just for example, these is my latest result for my on working blog : http://www.webpagetest.org/result/110803_SB_17PVH/).
I think I already have that part, just done differently from how you did it – tuurbo Aug 3 '11 at 21:00 if ($_SERVER'HTTP_IF_MODIFIED_SINCE' == gmdate('D, d M Y H:i:s \G\M\T', $last_modified)) is the missing piece. – toopay Aug 3 '11 at 21:04.
Yes, in theory the browser should pay attention to the Cache-Control, Expires, etc. information you're sending back, but in practice it's not always a good idea to trust the browser to do the right thing. What you might want to consider doing is adding a second step in your compress. Php script ... have it do a redirect to the actual compressed file, and append something like "?
Ts=". $last_modified_time to the path to the file. That way the URL will change when the file changes, and the browser will be much more likely to do the right thing and get the most recent file.
I've used a similar technique before.
I don't really want to use redirects :/ – tuurbo Aug 3 '11 at 21:00.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.