http headers - Force the browser to cache a .php -


i need browser cache large, static .php file. open via ajax , want add current page.

after research if found this

$seconds_to_cache = 3600; $ts = gmdate("d, d m y h:i:s", time() + $seconds_to_cache) . " gmt"; header("expires: $ts"); header("pragma: cache"); header("cache-control: max-age=$seconds_to_cache"); 

this works ie, not chrome , firefox.

here request

accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 accept-encoding gzip, deflate accept-language de-de,de;q=0.8,en-us;q=0.5,en;q=0.3 cache-control   max-age=0 connection  keep-alive content-type    application/x-www-form-urlencoded cookie  phpsessid=5dkvr42f4it8pnnnqpesj6l413 host    localhost referer http://localhost/mifa/suche.php user-agent  mozilla/5.0 (windows nt 6.1; wow64; rv:13.0) gecko/20100101 firefox/13.0.1 charset utf-8 

and here response header

cache-control   max-age=3600 connection  keep-alive content-type    text/html date    thu, 05 jul 2012 15:28:22 gmt expires thu, 05 jul 2012 16:28:22 gmt keep-alive  timeout=5, max=91 pragma  cache server  apache/2.2.21 (win32) mod_ssl/2.2.21 openssl/1.0.0e php/5.3.8 mod_perl/2.0.4 perl/v5.10.1 transfer-encoding   chunked x-powered-by    php/5.3.8 

what need change?

edit

apparently, ie not append cache-control max-age=0 request.

here js function of request

url = "includes/orte.php"; obj.onreadystatechange = rstate; obj.open("get", url, true); obj.setrequestheader("pragma", ""); obj.setrequestheader("cache-control", ""); obj.setrequestheader("charset", "utf-8"); obj.setrequestheader("content-type", "application/x-www-form-urlencoded"); obj.setrequestheader("connection", "close"); obj.send();  function rstate(){     if(obj.readystate == 4){         if (obj.status == 200){             //alert("response text ajax:\n" + obj.responsetext + "\nend response text");         }     } } 

the cache-control: max-age=0 header in request means asked browser refresh page, ignores cache.

access page without hitting refresh (e.g. focus address bar , hit enter) avoid this.

also, if page on https url, may have add public cache-control header, else browsers won't cache it.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -