title: Preventing iframe caching in browser
body: <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 &quot;back&quot; 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=&quot;webpage2.html?var=xxx&quot; /&gt;
    &lt;!-- stuff --&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>The <code>var</code> variable always changes. Although 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=&quot;webpage2.html?var=222&quot; /&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 id="update">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 a random number on the webpage.</li>
  <li>Outer page calls iframe, passing in a random number.</li>
  <li>Inner page displays a 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 id="visual-test">Visual Test</h2>
  <p>For a quick test, I load the page, navigate to another page, and then press &quot;back.&quot; 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 id="fiddler-test">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=&quot;http://ipv4.fiddler:1416/page1.aspx?var=0.21300034290246206&quot; /&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=&quot;http://ipv4.fiddler:1416/page1.aspx?var=0.4470929019483644&quot; /&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>