admin管理员组

文章数量:1315287

i have a iframe and it takes a while for for the content to e back. I can't avoid using the iframe, so i'm wondering if i can somehow:

  1. cache the content, so that when i revisit the page, it loads very fast.
  2. prefetch the page that has the iframe on it. Here I've tried using <link rel="prefetch" href="..." />, but it seems that it has no effect on the iframe

any ideas how to solve this issue? Can be a front end or a back end solution?

i have a iframe and it takes a while for for the content to e back. I can't avoid using the iframe, so i'm wondering if i can somehow:

  1. cache the content, so that when i revisit the page, it loads very fast.
  2. prefetch the page that has the iframe on it. Here I've tried using <link rel="prefetch" href="..." />, but it seems that it has no effect on the iframe

any ideas how to solve this issue? Can be a front end or a back end solution?

Share Improve this question edited Jun 20, 2013 at 20:48 Nathan Hughes 96.5k20 gold badges191 silver badges284 bronze badges asked Jun 20, 2013 at 19:39 PatrioticcowPatrioticcow 27.1k76 gold badges221 silver badges339 bronze badges 4
  • You could load the iframe but set display: none; until it's required. – Joe Commented Jun 20, 2013 at 19:49
  • @Joe. im not sure you get my point. I want the content cached or prefetch – Patrioticcow Commented Jun 20, 2013 at 20:04
  • I understand your point but it's not possible to prefetch the iframe content without loading it hidden and then displaying it. The user's browser caching the iframe content depends on the iframe site's cache headers. You could always fetch the remote site in PHP then serve it from your server in an iframe. However, this won't work if the remote content is dynamic. – Joe Commented Jun 20, 2013 at 20:08
  • @Joe i have age1.html that has a link to page2.html. page2.html has the iframe on it. How can i load the iframe in page1 and display it in page2 – Patrioticcow Commented Jun 20, 2013 at 20:44
Add a ment  | 

1 Answer 1

Reset to default 3

Loading the iframe content makes the browser cache the page in it, so that if you load it a second time later, the browser will simply fetch it from cache, unless your server is set up to always load the content afresh. I suspect that if you're seeing it reload the iframe's page each time you revisit it, you either forgot to indicate how long the page should be cached for, or your server isn't set up to say "this page has not been modified since ..." so the browser doesn't try to reload the page, or the page is served with a header that indicates it cannot be cached.

(If you want to preload the content for the first run, that's the same thing as loading it in the iframe, with the iframe hidden, and then showing it when the iframe content is ready.)

本文标签: javascripthow to prefetchcache iframe contentStack Overflow