您应该在WordPress上使用CDN的5个原因

tech2022-12-26  66

Nowadays it’s relatively inexpensive to use a Content Distribution Network (CDN) for your WordPress website, some are even free. While there are many benefits of using a CDN, they should be taken with a grain of salt.

如今,为您的WordPress网站使用内容分发网络(CDN)相对便宜,有些甚至是免费的。 尽管使用CDN有许多好处,但应随心所欲。

In this article you won’t find only hallelujahs for using a CDN, but I will give you 5 good reasons why you should be using a CDN with WordPress.

在本文中,您不会仅发现使用CDN的哈利路亚,但我将为您提供5个理由,说明为什么您应该在WordPress中使用CDN。

One important note: Even if you’re saying you are not using a CDN, you probably are. Almost all of the third party apps running on your site, like Facebook or Google Analytics are using CDNs to load their scripts. Craig gives further insight in his article about CDNs.

重要提示:即使您说的不是使用CDN,也可能是。 您网站上运行的几乎所有第三方应用程序(例如Facebook或Google Analytics(分析))都使用CDN来加载其脚本。 Craig在有关CDN的文章中提供了进一步的见解。

In this article I will focus on the CDN you actively turn on yourself however, which is quite easy if you use a WordPress caching plugin.

在本文中,我将重点介绍您主动打开自己的CDN,但是如果您使用WordPress缓存插件,这将非常容易。

1.速度 (1. Speed)

Let’s start with what most people consider the main selling point of a CDN: Speed. It is widely believed that using a CDN will increase the loading speed of your site.

让我们从大多数人认为CDN的主要卖点开始:速度。 人们普遍认为,使用CDN可以提高网站的加载速度。

While in many cases this is true, what you really should look at is the speed improvement. Going from 15 seconds to 6 seconds loading time after switching on a CDN might seem impressive, but still about 4 seconds longer than needed. It basically tells you your code sucks, even though some of your files are loading faster.

尽管在很多情况下是这样,但您真正应该看的是速度的提高。 开启CDN后,加载时间从15秒缩短到6秒似乎令人印象深刻,但仍比需要的时间长4秒左右。 它基本上告诉您即使某些文件加载​​速度更快,您的代码也很糟糕。

Going from 6 to 2 seconds however is a great improvement, and if it can be fully attributed to the CDN then it’s a useful addition. In this case your site is probably well optimized, and you need the CDN to speed up loading your heavier or large number of files.

但是,从6秒缩短到2秒是一个很大的改进,如果可以将其完全归因于CDN,那么它是一个有用的补充。 在这种情况下,您的站点可能已经过优化,您需要CDN来加快加载大量文件的速度。

What’s also very important is the capabilities and configuration of your web host. More often than not, a premium web host already has an internal CDN-like setup, where they serve up your static files from optimized file servers.

同样重要的是Web主机的功能和配置。 优质的Web主机通常已经具有内部CDN式的设置,可以在其中安装来自优化文件服务器的静态文件。

For example I am using a WordPress specialized host for one of my personal sites in the UK, where they have one of their data centers based in London. These guys have optimization running through their veins and it shows in the results I see. This is a good case of paying extra for a higher quality service.

例如,我在英国的一个个人站点中使用WordPress专用主机 ,在那里他们在伦敦拥有一个数据中心。 这些家伙在他们的血管中进行了优化,结果显示在我看到的结果中。 这是为高质量服务支付额外费用的好例子。

The above tests were performed at GTMetrix.com. The homepage has quite a lot or photos on it, which makes it in theory, ideal for a CDN. The site and images are fairly optimized though, and turning on a CDN gave a load time improvement of about… 0.3 seconds. Yep, that’s what you get for spending a bit more on hosting.

以上测试是在GTMetrix.com上进行的 。 主页上有很多照片,因此从理论上讲,它非常适合CDN。 不过,站点和图像已进行了相当优化,打开CDN可使加载时间缩短约0.3秒。 是的,这就是您在托管上花费更多的钱。

Lesson learned here: Make sure you actually need a CDN.

在这里获得的经验教训: 确保您确实需要CDN。

2.减轻负荷,保持稳定的速度 (2. Load Reduction and Consistent Speed)

Another main reason for using a CDN is for load reduction and the resulting consistent speed it gives you, especially when traffic spikes. When running your own server or using shared hosting, you might notice things slow down during these times. A CDN can help you to reduce or even prevent this effect.

使用CDN的另一个主要原因是为了减少负载,以及由此产生的一致速度,尤其是在流量高峰时。 在运行自己的服务器或使用共享主机时,您可能会注意到在这些时间里速度变慢。 CDN可以帮助您减少甚至防止这种影响。

Because CDNs are designed to handle massive loads of traffic, they won’t break when you suddenly become very popular. We used to call this the Slashdot-effect, and later the Digg-effect, back in the days. This was because becoming popular on these social platforms typically brought your average shared hosting account to its knees.

由于CDN旨在处理大量流量,因此当您突然变得非常受欢迎时,它们不会中断。 在过去,我们曾经将其称为Slashdot效应,后来称为Digg效应。 这是因为在这些社交平台上变得流行通常会使您的平均共享托管帐户屈服。

As with speed, using a CDN alone won’t always prevent downtime during traffic surges. If your main site/server is still required for loading dynamic files, it may still go down. Caching is the key here. Once you’ve enabled caching, then you can add a CDN. Always perform real load testing to make sure you’ve got it working correctly.

与速度一样,仅使用CDN并不总是可以防止流量激增期间的停机时间。 如果仍然需要您的主站点/服务器来加载动态文件,则它可能仍会关闭。 缓存是这里的关键。 启用缓存后,即可添加CDN。 始终执行真实的负载测试,以确保其正常工作。

3.走向全球 (3. Going Global)

The situation where you definitely should be using a CDN is when you want to reach a global audience. A decent CDN provider has servers spread out all over the globe, so there’s always one within a relatively small distance from where you’re connected to the Internet. This means even visitors in a country far, far away can experience your site as if they were sitting next to it.

当您想吸引全球受众时,绝对应该使用CDN的情况。 一家不错的CDN提供商将服务器分布在全球各地,因此,与您连接到Internet的位置相比,总是存在一个相对较小的距离。 这意味着即使是在遥远的国家/地区中的访问者也可以像坐在旁边一样来体验您的网站。

Of course, this still depends on the coverage of your CDN provider. I have one site with a surprisingly large amount of visitors from India. You would expect a benefit from using a CDN here. Well there is, but it doesn’t help that the files need to come all the way from Singapore, which is the closest location. It’s still closer than the UK, but quite a long way if you have to walk it. So make sure you check the coverage map of a provider first, taking into consideration that Point of Presence alone doesn’t always guarantee complete local coverage.

当然,这仍然取决于CDN提供程序的覆盖范围 。 我有一个网站,来自印度的访问者数量惊人地多。 您会期望从此处使用CDN受益。 好的,但是文件并不能一直从最近的新加坡来。 它仍然比英国更近,但是如果您必须步行的话,还有很长的路要走。 因此,请确保您首先检查提供商的覆盖图,并考虑到存在点本身并不能始终保证完整的本地覆盖范围。

Various page speed tools support testing from various geographic regions. So if you’re in the UK and your visitors are in the US, run your tests from the US.

各种页面速度工具支持来自不同地理区域的测试。 因此,如果您在英国,而访客在美国,请从美国进行测试。

4.节省成本 (4. Cost Savings)

Adding a CDN sounds expensive, so how can using a CDN actually save you money? Load reduction is a big one, especially when running your own servers. Using a CDN is, in most cases cheaper than adding more CPU or RAM. The same applies to shared hosting, there may not be a need to upgrade to a higher plan if you reduce your resource usage.

添加CDN听起来很昂贵,那么使用CDN如何才能真正为您省钱呢? 减少负载是一个很大的问题,尤其是在运行自己的服务器时。 在大多数情况下,使用CDN比添加更多的CPU或RAM便宜。 共享主机也是如此,如果您减少资源使用量,则可能无需升级到更高的计划。

Geo-distribution is another money saver. You could set up web servers in different data centers around the world, but utilizing a CDN is way cheaper.

地理分布是另一个省钱的方法。 您可以在世界各地的不同数据中心中设置Web服务器,但是使用CDN便宜得多。

There’s even a way to get a quality CDN for free, you can use CloudFlare. I’ve written about CloudFlare before and also covered a service called Incapsula. They offer a free CDN too, but focus more on security.

甚至还有一种免费获取优质CDN的方法,您可以使用CloudFlare。 我之前写过有关CloudFlare的文章 ,还介绍了一个名为Incapsula的服务。 他们也提供免费的CDN,但更多地关注安全性。

CloudFlare is basically an advanced CDN. You have all the benefits of a regular CDN like optimized servers, parallel downloading (since you’re using a different domain for your CDN) and DDoS protection.

CloudFlare基本上是高级CDN。 您可以享受常规CDN的所有好处,例如优化服务器,并行下载(因为您为CDN使用了其他域)和DDoS保护。

Apart from their core features, CloudFlare also adds their own special sauce, which they use to optimize your images and CSS/scripts (minification). There’s even an option to load your scripts asynchronously. The cost of all this juiciness? $0. You can literally save hundreds of GBs without spending a cent. Their coverage is quite good as well.

除了其核心功能之外,CloudFlare还添加了自己的特殊调味料,它们可用于优化图像和CSS /脚本(最小化)。 甚至还可以选择异步加载脚本。 这些多汁的代价? $ 0。 您实际上可以节省数百GB,而无需花费一分钱。 它们的覆盖范围也很好。

5. WordPress喜欢CDN (5. WordPress Loves CDNs)

It’s very easy to integrate a CDN with WordPress, due to it’s simple file structure.

由于CDN具有简单的文件结构,因此将CDN与WordPress集成非常容易。

There are many CDN plugins available at the WordPress Directory, and most providers offer their own plugin as well.

WordPress目录中提供了许多CDN插件,大多数提供商也提供了自己的插件。

Alternatively you can use one of the popular WordPress caching plugins, which not only gives you easy CDN integration but also provides other optimization features for your site.

另外,您可以使用一种流行的WordPress缓存插件,该插件不仅可以轻松实现CDN集成,还可以为您的站点提供其他优化功能。

结论 (Conclusion)

As you can see there are many great reasons for using a CDN for your WordPress site. There are hardly any downsides of using one.

如您所见,在您的WordPress网站上使用CDN的原因很多。 使用一个几乎没有任何缺点。

Always remember to check the coverage of the provider you intend to use. Also make sure you actually need a CDN, and never rely on it solely to speed up your site. Keep that in mind and your site should be loading in lightning fast times.

始终记得检查您打算使用的提供程序的覆盖范围。 另外,请确保您确实需要CDN,而不要仅仅依靠CDN来加快站点速度。 请记住这一点,您的网站应该在闪电般的快速加载中。

翻译自: https://www.sitepoint.com/5-reasons-why-you-should-be-using-a-cdn-with-wordpress/

相关资源:解决WordPress使用CDN后博文无法评论的错误
最新回复(0)