Avoid caching iframe in Safari

iframe.id = new Date().getTime(); // set different id or just use random number for cached iframe

I create embedded dialogs dynamically using iframes, but I never set an ID to them before (just kept a reference to the object). Safari tries to be efficient by restoring the last address to each frame after a refresh; and does this by mapping the iframe’s id to its address. So by assigning a random id to each new iframe, Safari can no longer assign the cached address.

***

The correct minimum set of headers which works in all of the mentioned browsers is the following:

Cache-Control: no-cache, no-store, must-revalidate Pragma: no-cache Expires: 0 

The PHP way would look like:

header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
header('Expires: 0'); // Proxies.

The Java/Servlet way would look like:

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.

The ASP.NET way would look like:

Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
Response.AppendHeader("Expires", "0"); // Proxies.

The Ruby on Rails way would look like:

response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" // HTTP 1.1. response.headers["Pragma"] = "no-cache" // HTTP 1.0. response.headers["Expires"] = "0" // Proxies. 

The plain HTML way would look like:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">

The Cache-Control is per the HTTP 1.1 spec for clients (and implicitly required by some browsers next toExpires), the Pragma is per the HTTP 1.0 spec for clients and proxies and Expires is per the HTTP 1.1 spec for clients and proxies. Other Cache-Control parameters are irrelevant if the abovementioned three are specified.

Note that when the page is served over HTTP and a header is present in both the HTTP response headers and the HTML meta tags, then the one specified in the response header will get precedence over the HTML meta tag. The HTML meta tag will only be used when the page is viewed from local disk file system. See also W3 HTML spec chapter 5.2.2. Take care with this when you don’t specify them programmatically, because the webserver can namely include some default values. To verify the one and other, you can see/debug them using Firebug Netpanel.

Source :

http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers

http://www.webdeveloper.com/forum/showthread.php?t=150101

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s