gpt4 book ai didi

javascript - 加载 html 或 JavaScript 文件作为 iframe 源

转载 作者:行者123 更新时间:2023-11-28 03:14:57 26 4
gpt4 key购买 nike

有什么区别-

  • 加载构建整个 html 的 JavaScript 文件(从创建 head, body tags to rest) 等应用相关人员。
  • 加载包含框架(例​​如 head、body 标签)和构建页面其余部分和其他人员的 JavaScript 的 html。

我需要采用这两者之间的最佳方法来填充 iframe:

ifrm.src="http://somewhereintheuniverse.com/test.js"

ifrm.src="http://somewhereintheuniverse.com/widget.html"

两者的资源缓存机制是否相同?描述这两种方法的优缺点的建议将不胜感激。

最佳答案

将整个 html 放在一个 html 文件中会更快,因为构建 html,或者更确切地说,使用 JavaScript 修改 DOM,由于多种原因会很慢,请参见 But why's the browser DOM still so slow after 10 years of effort?

因此,如果可能的话,如果您纯粹追求速度,我会选择将所有 html 加载到一个文件中的选项,而不是使用 JavaScript 构建它。 JavaScript 的优点在于它为您提供了灵 active ,并且可以消除列表等内容中的重复代码。但最好在服务器端摆脱代码重复并只返回一个 html 文件。

注意缓存是一样的。 DOM 操作将是最大的减速。

关于javascript - 加载 html 或 JavaScript 文件作为 iframe 源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28668946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com