浏览器是否多次加载相同的脚本?

时间:2016-04-11 01:57:02

标签: javascript html google-chrome internet-explorer firefox

我正在尝试使用网页生成工具,并且在某些情况下,相同的脚本会被多次包含(因为某些依赖性)。我应该担心它还是在浏览器级别解决了多次加载完全相同的文件

页码中的示例:

<script src="../../Scripts/thescript.js"></script>
...
...
<script src="../../Scripts/thescript.js"></script>
...
..
<script src="../../Scripts/thescript.js"></script>

thescript.js 将被加载多少次?

这个问题看起来像是重复的 Will inserting the same `<script>` into the DOM twice cause a second request in any browsers?

然而,那是6年前,浏览器发生了很大的变化,可能不再相关,而且它还没有被接受的答案。所以我想保持这个,并希望得到一些好的建议。

作为一个快速测试,我制作了这个小页面代码:

<html>
  <head>
    <script src='../Scripts/ckeditor/ckeditor.js'></script> 
    <script src='../Scripts/ckeditor/ckeditor.js'></script> 
  </head>
  <body>
    PAGE BODY
    <script src='../Scripts/ckeditor/ckeditor.js'></script>
    <script src='../Scripts/ckeditor/ckeditor.js'></script> 
    <script src='../Scripts/ckeditor/ckeditor.js'></script> 
    </script>
  </body>
</html>

如果我检查了 Chrome (版本:49.0.2623.110 m): enter image description here

我得到了我所希望的。

Edge (版本:25.10586.0.0)中: enter image description here

不是我所希望的。但加载时间越来越好。

Firefox (版本:42.0): enter image description here

Internet Explorer (版本11.162.10586.0) enter image description here

然而,获取304(未修改)并从缓存加载看起来对我来说很好。

对我来说,今天的浏览器可以按预期处理这类事情,因此在文档中多次引用完全相同的js文件时没有问题。除非你感到不舒服(0.5 - 1毫秒)花费时间来确定是否加载脚本或不。可能通过文档并“清理”它会使性能比离开它更糟糕。还有其他意见吗?

0 个答案:

没有答案
相关问题