问题描述
我正在尝试缓存客户端的某些文档,以便更快地在它们之间切换。
I'm trying to cache some documents client-side in order to switch between them faster.
文档已经加载到iframe中,所以这是一个问题关于如何在浏览器中本地缓存它。
The documents have been loaded in an iframe, so it's a question on how to cache it locally within the browser.
我的方法是有一个变量,item,然后再做
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);
但是,这种方法会在注入持有者时不断重新加载iframe src。
However, this method keeps reloading the iframe src, when injected on to the holder.
客户端iframe缓存的任何好方法?
Any good methods for client-side iframe caching?
推荐答案
iframe
实际上不会触发页面刷新,直到它被添加到 dom
。我猜你保留了一个 iframe
的实例,但是没有把它添加到dom中,直到看到它为止。这种方法效果不好。我建议使用cssdisplay:none加载它并隐藏,然后在需要时显示它。
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.
另外,请远离 iframes
。我建议使用ajax将数据加载到 div
,然后隐藏 div
。
On a different note, stay away from iframes
. I would suggest using ajax to load the data in to a div
and then hide that div
.
这篇关于客户端iframe缓存的一种好方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!