[ACCEPTED]-How do I clear the cache of an iFrame?-html

Accepted answer
Score: 17

The first choice is probably to control 6 browser caching for the iframe page from 5 your web server either with HTTP headers 4 or with <meta> tags (see reference).


If you can't change 3 those, then you can set a .src in the iframe 2 that has a different query parameter each 1 time to go around caching.

For example:

iframeObj.src = "http://www.example.com/page/myframe.html?random=" + (new Date()).getTime() + Math.floor(Math.random() * 1000000);
Score: 2

This is something you should do on the server 1 side, controlled via HTTP headers like so:

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sun, 29 Jul 2012 00:00:00 GMT"); // some day in the past
Score: 1

You could do something like

<iframe src="<?php echo $url.'#nocache'.time(); ?>">

Which would allow 3 for GET parameters in the URL without also 2 having to worry about whether to use ? or 1 & for your random.

More Related questions