在浏览器preventing IFRAME缓存 [英] Preventing iframe caching in browser

查看:152
本文介绍了在浏览器preventing IFRAME缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么prevent Firefox和Safari缓存从iframe中的内容?

How do you prevent Firefox and Safari from caching iframe content?

我有一个iframe到一个页面上不同的网站一个简单的网页。无论是外页和内页有HTTP响应头,以prevent缓存。当我点击浏览器返回按钮,外页正常工作,但无论怎样,浏览器总是检索的iFrame网页的缓存。 IE浏览器工作得很好,但Firefox和Safari给我找麻烦。

I have a simple webpage with an iframe to a page on a different site. Both the outer page and the inner page have HTTP response headers to prevent caching. When I click the "back" button in the browser, the outer page works properly, but no matter what, the browser always retrieves a cache of the iframed page. IE works just fine, but Firefox and Safari are giving me trouble.

我的网页看起来是这样的:

My webpage looks something like this:

<html>
  <head><!-- stuff --></head>
<body>
  <!-- stuff -->
  <iframe src="webpage2.html?var=xxx" />
  <!-- stuff -->
</body>
</html>

VAR 变量总是变化。尽管iframe的网址已经改变(因此,浏览器应该使该页面一个新的请求),浏览器只是获取缓存内容。

The var variable always changes. Despite the fact that the URL of the iframe has changed (and thus, the browser should be making a new request to that page), the browser just fetches the cached content.

我已经检查了HTTP请求和响应来回,我注意到,即使外部页面中包含&LT; IFRAME SRC =?webpage2.html VAR = 222/&GT; ,浏览器仍然会获取 webpage2.html?无功= 111

I've examined the HTTP requests and responses going back and forth, and I noticed that even if the outer page contains <iframe src="webpage2.html?var=222" />, the browser will still fetch webpage2.html?var=111.

下面是我到目前为止已经试过:

Here's what I've tried so far:


  • 更改iframe网址随机变量值

  • 添加过期,缓存控制,和附注头到外部网页

  • 添加过期,缓存控制,和附注标头内的网页

我无法做任何JavaScript的技巧,因为我封锁的同源策略。

I'm unable to do any JavaScript tricks because I'm blocked by the same-origin policy.

我跑出来的想法。有谁知道如何从缓存iFrame内容阻止浏览器?

I'm running out of ideas. Does anyone know how to stop the browser from caching the iframed content?

我安装Fiddler2丹尼尔建议进行另一个测试,不幸的是,我仍然得到同样的结果。

I installed Fiddler2 as Daniel suggested to perform another test, and unfortunately, I am still getting the same results.

这是我进行的测试:


  1. 外页生成使用随机数的Math.random()在JSP中。

  2. 外页显示在网页上的随机数。

  3. 外页面调用IFRAME,传递随机数。

  4. 内页显示的随机数。

  1. Outer page generates random number using Math.random() in JSP.
  2. Outer page displays random number on webpage.
  3. Outer page calls iframe, passing in random number.
  4. Inner page displays random number.

通过这个测试,我可以清楚地看到哪些网页正在更新,哪些页面缓存。

With this test, I'm able to see exactly which pages are updating, and which pages are cached.

有关快速测试,我加载页面,导航到另一个页面,然后preSS背。下面是结果:

For a quick test, I load the page, navigate to another page, and then press "back." Here are the results:

原始网页:


  • 外页:0.21300034290246206

  • 内页:0.21300034290246206

离开页面,则回击:


  • 外页:0.4470929019483644

  • 内页:0.21300034290246206

这表明,内页被缓存,即使外部页面与URL中的不同的GET参数调用它。出于某种原因,浏览器是忽略的iframe请求一个新的URL的事实;它只是加载了旧的。

This shows that the inner page is being cached, even though the outer page is calling it with a different GET parameter in the URL. For some reason, the browser is ignoring the fact that the iframe is requesting a new URL; it simply loads the old one.

果然,提琴手证实了同样的事情。

Sure enough, Fiddler confirms the same thing.

(我加载页面。)

外网页时调用。 HTML:

Outer page is called. HTML:

0.21300034290246206
<iframe src="http://ipv4.fiddler:1416/page1.aspx?var=0.21300034290246206" />

<一个href=\"http://ipv4.fiddler:1416/page1.aspx?var=0.21300034290246206\">http://ipv4.fiddler:1416/page1.aspx?var=0.21300034290246206被调用。

(我导航离开该页面,然后还击。)

(I navigate away from the page and then hit back.)

外网页时调用。 HTML:

Outer page is called. HTML:

0.4470929019483644
<iframe src="http://ipv4.fiddler:1416/page1.aspx?var=0.4470929019483644" />

<一个href=\"http://ipv4.fiddler:1416/page1.aspx?var=0.21300034290246206\">http://ipv4.fiddler:1416/page1.aspx?var=0.21300034290246206被调用。

那么,从这个测试,它看起来好像Web浏览器不缓存的页面,但它的缓存iframe的URL,然后做出对缓存的URL的新请求。不过,我还是难倒如何解决这个问题。

Well, from this test, it looks as though the web browser isn't caching the page, but it's caching the URL of the iframe and then making a new request on that cached URL. However, I'm still stumped as to how to solve this issue.

有没有人对如何阻止Web浏览器的任何想法从缓存中添加iframe网址?

Does anyone have any ideas on how to stop the web browser from caching iframe URLs?

推荐答案

请的iframe点的URL到您网站上的一个网页,其中充当代理检索并返回iframe的实际内容。现在你不再受同源策略的约束。

Make the URL of the iframe point to a page on your site which acts as a proxy to retrieve and return the actual contents of the iframe. Now you are no longer bound by the same-origin policy.

这篇关于在浏览器preventing IFRAME缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆