简体   繁体   English

在iframe中加载脚本代码

[英]Script tag loading inside Iframes

I've been trying to find an answer to this but could never find one: 我一直在努力寻找答案,但是找不到:

I have four iframes loading on a parent page. 我在父页面上加载了四个iframe。 Each of these I frames have javascript to be executed (slightly different JS in each one). 这些I框架中的每一个都有要执行的javascript(每个框架中的JS略有不同)。

Currently, I've bundled all that JS into one file, which is in tag in each of the frames. 目前,我已将所有JS捆绑到一个文件中,该文件在每个框架的标签中。

The behaviour I see is that the browser emits only one request to that script, since it's the same in each frame. 我看到的行为是,浏览器仅对该脚本发出一个请求,因为每个框架中的请求都相同。

My question is: What if I wanted smaller bundles, by splitting that JS file into 4 smaller ones. 我的问题是:如果我想要较小的捆绑包,可以将该JS文件分成4个较小的捆绑包,该怎么办。 how are script tags loaded inside an iframe ? 如何在iframe中加载脚本代码?

If they're loaded async: I might gain some performance from it. 如果它们被异步加载:我可能会从中获得一些性能。 If they're loaded one after the other: Then having a larger bundle and avoiding multiple round trips might be better. 如果将它们一个接一个地装载:那么使用更大的捆并避免多次往返可能会更好。

Iframes work almost exactly like parent pages do. iframe的工作几乎与父页面完全一样。 Think of it like opening up several tabs in your browser at the same time, each one tries to load as quickly as possible, independent of the other pages. 可以将其想像为同时在浏览器中打开多个标签,每个标签都试图尽快加载,而与其他页面无关。

Using a single large bundle means that once it has finished downloading in any iframe, the browser will cache it and all other iframes requesting it will load faster from the cache. 使用单个大捆绑包意味着一旦它完成了在任何iframe中的下载,浏览器就会对其进行缓存,而请求它的所有其他iframe将从缓存中更快地加载。

Using smaller bundles means that each iframe might finish load sooner if it's particular script finishes before the other iframes, but there's no guarantee which order they'll finish. 使用较小的包意味着,如果特定的脚本在其他iframe之前完成,则每个iframe可能会更快地完成加载,但是无法保证它们将完成哪个顺序。 They'll all try to asynchronously load their respective files. 他们都将尝试异步加载各自的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM