为什么我应该为 jQuery 使用 Google 的 CDN? [英] Why should I use Google's CDN for jQuery?

查看:31
本文介绍了为什么我应该为 jQuery 使用 Google 的 CDN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对某些人来说可能很明显,但我一直在想:我为什么要依赖 Google 的服务器为我的网站托管 jQuery?

This may be obvious to some, but I've been wondering: why should I depend on Google's server to host jQuery for my site?

仅仅是因为这样加载速度更快吗?

Is it only because it loads faster this way?

推荐答案

这是因为:

  1. 它增加了可用的并行性.
    (大多数浏览器一次只能从任何给定站点下载 3 或 4 个文件.)

  2. 它增加了缓存命中的机会.
    (随着越来越多的网站遵循这种做法,更多的用户已经准备好了文件.)

  3. 它确保负载尽可能小.
    (Google 可以将文件预压缩为多种格式(如 GZIP 或 DEFLATE).这使得下载时间非常短,因为它是超级压缩的,并且不会即时压缩.)

  4. 它减少了服务器使用的带宽量.
    (Google 基本上提供免费带宽.)

  5. 它确保用户将获得地理位置接近的响应.
    (Google 在世界各地设有服务器,进一步降低了延迟.)

  6. (可选)他们会自动使您的脚本保持最新状态.
    (如果您喜欢坐享其成",您可以随时使用 他们提供的任何脚本的最新版本.这些可以修复安全漏洞,但通常只会破坏你的东西.)
  1. It increases the parallelism available.
    (Most browsers will only download 3 or 4 files at a time from any given site.)

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

  3. 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.)

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

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

  6. (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.)

这篇关于为什么我应该为 jQuery 使用 Google 的 CDN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆