开发者

When an iFrame imports a JS library, does the browser actually import the library a second time?

开发者 https://www.devze.com 2023-03-22 23:55 出处:网络
I\'ve developed a Google-home like portal for my school, and these wid开发者_开发技巧gets all work as separate iFrames. In creating this, I noticed that you must re-import JS libraries in each iFrame.

I've developed a Google-home like portal for my school, and these wid开发者_开发技巧gets all work as separate iFrames. In creating this, I noticed that you must re-import JS libraries in each iFrame.

My question is this: would it be terribly inefficient if multiple iFrames imported the same library? Would the client have to download the same library multiple times? If so, is there a way to use the same library you already imported in the parent?

Thanks!


It gets cached by the browser so the browser uses it from the cache itself.


No, once it's loaded, it's cached by the browser. This is why using JQuery from the Google CDN is beneficial because if anybody has visited any other website which has pulled JQuery from that same URL, it'll be pre-cached on their browser when they visit your site, and you get a bonus :)

0

精彩评论

暂无评论...
验证码 换一张
取 消