Clear iframe cache


#1

I have built an app which includes an iframe in the index.html page.
The problem is the content of this iframe stays in cache and it keeps trying to load the same instead of loading from the server.
Could anyone please suggest how to clear the cache of the iframe only and not necessarily the app cache.

Thanks,
Aadil


#2

So it’s highly recommended to not use iframes. I would suggest rewriting that part of your app to avoid it if you can.

Though to answer your question, there isn’t a way for the app to really do it. You can set some meta in the index html head but that’s never a guarantee it will work on all platforms.

<meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">```

Another alternative, is if you can load a "new" file, it won't pull the cached file. The way to do this is like

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

The "?random" parameter will force a full reload since you're generating a random number that changes on every load. 

Good luck!

#3

Thank you! This helps alot.