Note that there are some explanatory texts on larger screens.

plurals
  1. POPreventing iframe caching in browser
    primarykey
    data
    text
    <p>How do you prevent Firefox and Safari from caching iframe content?</p> <p>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.</p> <p>My webpage looks something like this:</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;!-- stuff --&gt;&lt;/head&gt; &lt;body&gt; &lt;!-- stuff --&gt; &lt;iframe src="webpage2.html?var=xxx" /&gt; &lt;!-- stuff --&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The <code>var</code> 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.</p> <p>I've examined the HTTP requests and responses going back and forth, and I noticed that even if the outer page contains <code>&lt;iframe src="webpage2.html?var=222" /&gt;</code>, the browser will still fetch <code>webpage2.html?var=111</code>.</p> <p>Here's what I've tried so far:</p> <ul> <li>Changing iframe URL with random var value</li> <li>Adding Expires, Cache-Control, and Pragma headers to outer webpage</li> <li>Adding Expires, Cache-Control, and Pragma headers to inner webpage</li> </ul> <p>I'm unable to do any JavaScript tricks because I'm blocked by the same-origin policy. </p> <p>I'm running out of ideas. Does anyone know how to stop the browser from caching the iframed content?</p> <h1>Update</h1> <p>I installed Fiddler2 as Daniel suggested to perform another test, and unfortunately, I am still getting the same results.</p> <p>This is the test I performed:</p> <ol> <li>Outer page generates random number using <code>Math.random()</code> in JSP.</li> <li>Outer page displays random number on webpage.</li> <li>Outer page calls iframe, passing in random number.</li> <li>Inner page displays random number.</li> </ol> <p>With this test, I'm able to see exactly which pages are updating, and which pages are cached.</p> <h2>Visual Test</h2> <p>For a quick test, I load the page, navigate to another page, and then press "back." Here are the results:</p> <p>Original Page:</p> <ul> <li>Outer Page: 0.21300034290246206</li> <li>Inner Page: 0.21300034290246206</li> </ul> <p>Leaving page, then hitting back:</p> <ul> <li>Outer page: 0.4470929019483644</li> <li>Inner page: 0.21300034290246206</li> </ul> <p>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.</p> <h2>Fiddler Test</h2> <p>Sure enough, Fiddler confirms the same thing.</p> <p>(I load the page.)</p> <p>Outer page is called. HTML:</p> <pre><code>0.21300034290246206 &lt;iframe src="http://ipv4.fiddler:1416/page1.aspx?var=0.21300034290246206" /&gt; </code></pre> <p><a href="http://ipv4.fiddler:1416/page1.aspx?var=0.21300034290246206" rel="noreferrer">http://ipv4.fiddler:1416/page1.aspx?var=0.21300034290246206</a> is called.</p> <p>(I navigate away from the page and then hit back.)</p> <p>Outer page is called. HTML:</p> <pre><code>0.4470929019483644 &lt;iframe src="http://ipv4.fiddler:1416/page1.aspx?var=0.4470929019483644" /&gt; </code></pre> <p><a href="http://ipv4.fiddler:1416/page1.aspx?var=0.21300034290246206" rel="noreferrer">http://ipv4.fiddler:1416/page1.aspx?var=0.21300034290246206</a> is called.</p> <p>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.</p> <p>Does anyone have any ideas on how to stop the web browser from caching iframe URLs?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload