gpt4 book ai didi

jquery - 这会对我网站的加载时间产生负面影响吗?

转载 作者:行者123 更新时间:2023-12-01 08:33:17 25 4
gpt4 key购买 nike

我正在从像这样的单独 HTML 文件加载网站的部分内容(页眉、页脚和导航)

    $(function () {
$("#navbar").load("nav.html");
$("#header").load("header.html");
$("#footer").load("footer.html");
});

我这样做是为了让编辑整个网站的某些元素变得更容易,一旦我开发了更多页面,完成的项目将有大约 20-30 个页面。

问题不在于它们的实际加载,而是它们按预期正确显示。

<小时/>

我的问题:

将这些元素中的每一个都保留在每个 HTML 文件中,然后如果我需要编辑,则返回到每个元素,这样对成品的性能是否更好?

最佳答案

我不认为这会对性能产生任何重大影响。

然而,设计的影响是巨大的。 DRY——不要重复自己。这很烦人并且容易出错。

为了更好的可读性和可维护性而牺牲一些性能是很常见的,因为这通常是正确的选择。

不要空话,这里是令人惊叹的 Jon Skeet 的摘录(C# 深入,第四版,p399)

As a general principle, I wouldn’t start making any changes to your code to improve performance before you’ve measured performance in a meaningful and repeatable way and set goals for it. If you’re not careful, you can complicate your code in the name of optimization, only to find out that even if you massively improved the performance of one or two methods, those methods weren’t on a critical path for the application anyway

如果您确实决定进行一些基准测试,您不妨考虑采用非 js 方式。

<object data="includes/header.html" type="text/html"> </object>

如果存在性能差异,我希望纯 html 方法会更快。

关于jquery - 这会对我网站的加载时间产生负面影响吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59813846/

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