gpt4 book ai didi

javascript - 许多 CDNjs 与一个缩小的本地 js

转载 作者:数据小太阳 更新时间:2023-10-29 03:48:27 24 4
gpt4 key购买 nike

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.3.1/jquery.inputmask.bundle.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/numeral.js/1.5.3/numeral.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Ladda/1.0.0/spin.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Ladda/1.0.0/ladda.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-modal/2.2.6/js/bootstrap-modalmanager.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-modal/2.2.6/js/bootstrap-modal.min.js"></script>

对比

<script src="/myMin.js">

(myMin.js 将包含所有连接在一起并缩小的 js 文件)什么是最好的性能?我用的是cdnjs,因为它解决了其他地区的人直接从我的服务器下载js文件的问题。例如,亚洲人不必从美国服务器下载我的 js 文件,这是一个巨大的性能问题。 cdnjs 帮助我将 js 文件分散到全局各地。由于 cdnjs 是异步下载的,所以什么时候优先使用 myMin.js

最佳答案

我会说使用大量 CDN 引用更好,原因很简单,HTTP/2

我相信,Cloudflare 支持 HTTP/2,因此拥有多个单一用途脚本比一个组合脚本更好。

来自他们题为 "HTTP/2 for Web Developers" 的博文,名为 "Stop Concatenating Files" 的部分特别相关:

However, concatenating files is no longer a best practice in HTTP/2. While concatenation can still improve compression ratios, it forces expensive cache invalidations. Even if only a single line of CSS is changed, browsers are forced to reload all of your CSS declarations.

In addition, not every page in your website uses all of the declarations or functions in your concatenated CSS or JavaScript files. After it’s been cached, this isn’t a big deal, but it means that unnecessary bytes are being transferred, processed, and executed in order to render the first page a user visits. While the overhead of a request in HTTP/1.1 made this a worthwhile tradeoff, it can actually slow down time-to-first-paint in HTTP/2.

Instead of concatenating files, web developers should focus more on optimizing caching policy. By isolating files that change frequently from ones that rarely change, it’s possible to serve as much content as possible from your CDN or the user’s browser cache.

既然 HTTP/2 是 pretty widely supported,我们都需要开始质疑这些提高性能的标准技巧.

关于javascript - 许多 CDNjs 与一个缩小的本地 js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38803203/

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