如何禁止页面在safari中缓存

基本上safari会缓存所有页面以便加速访问。如果要禁止页面在safari中缓存,常用的header肯定要加上的

<?php

header(”Expires: Mon, 26 Jul 1997 05:00:00 GMT”); // Date in the past

header(”Last-Modified: ” . gmdate(”D, d M Y H:i:s”) . ” GMT”); // always modified

header(”Cache-Control: no-store, no-cache, must-revalidate, max-age=0″); // HTTP/1.1

header(”Cache-Control: post-check=0, pre-check=0″, false);

header(”Pragma: no-cache”); // HTTP/1.0

?>

加上上面这些header,可以让页面在大多数浏览器中都不缓存。但还是有个问题,上面的代码对safari的前进和后退不起作用,safari还是会在缓存里面读取数据。要做到完全禁止,根据官方的Safari Developer FAQ,还需要在页面中加上一个iframe。加上iframe后的页面,safari永远不缓存。

<iframe style=”height:0px;width:0px;visibility:hidden” src=”about:blank”>

 this frame prevents back forward cache

</iframe>