gpt4 book ai didi

javascript - 我应该在优化的 javascript 构建中嵌入第三方 javascript 库吗?

转载 作者:行者123 更新时间:2023-12-02 05:05:33 24 4
gpt4 key购买 nike

我正在使用优秀的 requirejs用于压缩 Web 应用程序代码的优化器。

该应用程序使用了大量第三方库。我有几个选择:

  • 让用户从我的服务器上单独下载所有第三方库
  • 如果可用,让用户从 CDN 下载所有第三方库
  • 用户要求在单个文件中生成所有这些库的“压缩”版本

现在,我知道缓存和/或 CDN 将有助于减少获取每个单独的库所需的时间,但是如果我有 15 个库,我仍然会得到 15 个 http 请求;如果我的应用程序的实际代码最终在一个或两个相对较小的文件中提供服务,那就更烦人了。

那么每种方法的优缺点是什么?另外,我想如果我将这些库捆绑在我的应用程序中(而不是指向 CDN ?),我实际上会“重新分发”(在常见的 FOOS 许可证的意义上)

欢迎任何经验/想法。

谢谢。

最佳答案

你可以看看Why should I use Google's CDN for jQuery?问题,为什么 CDN 是更好的解决方案。

It increases the parallelism available. (Most browsers will only download 3 or 4 files at a time from any given site.)

It increases the chance that there will be a cache-hit. (As more sites follow this practice, more users already have the file ready.)

It ensures that the payload will be as small as possible. (Google can pre-compress the file in a wide array of formats (like GZIP or DEFLATE). This makes the time-to-download very small, because it is super compressed and it isn't compressed on the fly.)

It reduces the amount of bandwidth used by your server. (Google is basically offering free bandwidth.)

It ensures that the user will get a geographically close response. (Google has servers all over the world, further decreasing the latency.)

(Optional) They will automatically keep your scripts up to date. (If you like to "fly by the seat of your pants," you can always use the latest version of any script that they offer. These could fix security holes, but generally just break your stuff.)

关于javascript - 我应该在优化的 javascript 构建中嵌入第三方 javascript 库吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12112570/

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