为什么建议从 CDN 加载 jQuery 或任何其他库?
一种不言自明的问题:为什么建议从 CDN 加载 jQuery 或任何其他库?
Kind of self-explanatory question: Why is it recommended loading jQuery or any other library from a CDN?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
据我所知,有两个主要原因:
1 - 它可以通过提供更接近客户端的路径来加快托管文件的交付速度。
2 - 它可以为常用文件提供缓存优势,因为用户可能已经从同一个 CDN 下载了该文件
Two main reasons as far as i know:
1 - It can speed delivery of the hosted files by providing a more proximate route to the client.
2 - It can provide caching benefits for commonly used files since the user may have already downloaded the file from the same cdn
@Matt 击中要害。除了 CDN 之外,您还可以回退到本地版本的 jQuery,以防 CDN 出现故障。下面的例子:
@Matt hit the nail on the head. In addition to a CDN, you can do a fallback to your local version of jQuery in case the CDN goes down. Example below:
原因有很多,但以下是一些突出的原因:
很多人说依赖CDN有风险,如果CDN宕机了怎么办?这是事实,但很可能您的网站比大公司更有可能失败。话虽如此,如果 CDN 确实出现故障,可以使用一些方法回退到您网站上托管的版本。
There are many reasons, but here are a few that stand out:
Many people say that it is risky to rely on the CDN, as what happens if the CDN goes down. This is true, but most likely your site will be more likely to go down that the big guys. That being said, there are approaches that can be used to have a fallback to a version hosted on your site if the CDN does go down.