将CDN用于js和类似资源比使用本地更好吗? [英] Is it better to use CDN for js and similar resources vs local?

查看:450
本文介绍了将CDN用于js和类似资源比使用本地更好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于将所有内容存储在本地,并确保即使没有互联网连接,我的站点也能在本地服务器上运行。从那以后,这就是我的原则,以便我的网站可以脱机独立运行,并且最特别地是用于开发阶段,其中页面刷新非常快,即使没有互联网,我也可以继续开发我的网站。

I have a habit of storing everything locally and making sure my site is able to run even on local server without internet connection. This has been my principle ever since so that my site can run stand alone offline, and most specially for developing phase where my page refreshes are super quick and I can continue to develop my sites even without internet.

因此,在我所有的Web应用程序和站点中,我总是下载所需的包和库,并在本地链接到包含和不包含的包。

So in all my web applications and sites, I always download the packages and libraries I need and locally link to them for includes and what not.

我知道越来越多的人通过公共CDN和其他东西链接/导入库,所以我想知道这样做是否有任何真正的好处?

I know more and more people are linking / importing libraries via public CDNs and stuff so I was wondering if there's any real SIGNIFICANT benefits to doing that?

显而易见(随时可以纠正我):

I have identified the obvious (feel free to correct me):

本地
-更快的开发经验
-对其他可能破坏$ b $的服务器的零依赖b-更快的用户体验(?),因为站点页面可以快速执行已与本地服务器上的文件/库一起工作(本地化)

PRO LOCAL - faster development experience - zero dependency on other servers that may break - faster user experience (?) since the site pages executes rapidly working with files/libraries on the same server already (localized)

PRO CDN
-保存网站空间(但在当今世界,这似乎微不足道..在一个典型的站点中,您只能节省大约10-20mb的空间,而在当今的大型方案中,这是什么?便宜的服务器以及其他所有东西)

PRO CDN - saves web space (but in today's world, this seems insignificant.. in a typical site you're able to save maybe 10-20mb worth of space only and what is that in the grand scheme of things nowadays and cheap servers and all)


  • 服务器上的打火机(?)=我实际上在想这个。从CDN加载会减轻服务器的处理器ram和I / o磁盘上的负担,还是会变得更糟,因为执行文档(例如index.php)需要花费更多的时间来占用线程/内存/ CPU周期? / li>
  • lighter on server (?) = I'm actually wondering about this. Will loading from a CDN be lighter on the server's processor ram and i/o disk, or will it be worse since the executing document (eg. index.php) takes bit longer to finish there by hogging threads/mem/cpu cycles?

谢谢。

推荐答案

CDN的好处不是(也不应该)对您有利。适用于您的客户/用户。使用CDN文件-特别是对于像jQuery这样的广泛使用的库(或任何其他大库)-意味着它们将从它们附近的物理位置接收文件的缓存副本。在大多数情况下,对大型图书馆使用流行的CDN意味着用户还已经从其他人的网站下载了该资源,因此该文件将被本地缓存在其浏览器中。

The benefit of a CDN is not (and should not be) for you. It is for your customers / users. Using CDN files - especially for widely used libraries like jQuery (or any other big library) - means they will receive a cached copy of the file from a physical location near them. In most cases, using a popular CDN for big libraries means the user has also downloaded that resource before - from someone else's site - so the file will be cached locally in their browser.

这有助于减少用户花费的时间来下载文件。在所有情况下,这都不关乎服务器的负载或开发能力,而是边缘情况的最小保证。首先考虑您的用户!

This helps reduce the time your user spends downloading files. It is not about your server load or your development ability in all but the smallest margin of edge cases. Think about your users first!

对于大多数静态文件使用CDN绝对对您的用户更好。

Using a CDN for most static files is strictly better for your users.

这篇关于将CDN用于js和类似资源比使用本地更好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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