admin管理员组

文章数量:1291050

I'm trying to cache some documents client-side in order to switch between them faster.

The documents have been loaded in an iframe, so it's a question on how to cache it locally within the browser.

My method was to have a variable, item, and then do

if (item.cache) {
    $('.holder', someElem).html(item.cache);
    return;
}

item.cache = $('<iframe....');
$('.holder', someElem).html(item.cache);

However, this method keeps reloading the iframe src, when injected on to the holder.

Any good methods for client-side iframe caching?

I'm trying to cache some documents client-side in order to switch between them faster.

The documents have been loaded in an iframe, so it's a question on how to cache it locally within the browser.

My method was to have a variable, item, and then do

if (item.cache) {
    $('.holder', someElem).html(item.cache);
    return;
}

item.cache = $('<iframe....');
$('.holder', someElem).html(item.cache);

However, this method keeps reloading the iframe src, when injected on to the holder.

Any good methods for client-side iframe caching?

Share Improve this question asked Jan 24, 2011 at 15:56 freeallfreeall 3,1984 gold badges26 silver badges31 bronze badges 1
  • If you want the opposite- do not cache iframe- see Refresh iFrame (Cache Issue) – Michael Freidgeim Commented Jun 3, 2021 at 2:41
Add a ment  | 

2 Answers 2

Reset to default 4

The iframe doesn't actually trigger a page refresh until it has been added to the dom. I am guessing you keep an instance of the iframe but not add it to the dom until its time to see it. This method doesn't work well. I would suggest using css "display:none" to load it and hide and then show it when you need it.

HTTP has caching built in. Mark Nottingham has written a decent overview. Setting the Cache-Control and Expires headers should be enough for what you describe.

本文标签: javascriptA good method for clientside iframe cachingStack Overflow