wordpress打开缓存_WordPress缓存指南

本文深入探讨了WordPress网站的缓存技术,包括客户端和服务器端缓存,以及HTTP压缩、CDN使用和图像优化等优化技术。介绍了WordPress中流行的缓存插件,如Comet Cache、WP Super Cache和W3 Total Cache,强调了缓存对提高网站性能和用户体验的重要性。
摘要由CSDN通过智能技术生成

wordpress打开缓存

When a site isn’t working the way it’s intended to, I’m sure you’ve asked yourself — “Should I clear the cache?”

当网站无法正常运行时,我确定您已经问过自己:“我应该清除缓存吗?”

Caching has been a part of our vocabulary, thanks to web browsers and their implementation of the same, but in this post, let’s try to go beyond the layman’s understanding of caching and implement it in our website to increase efficiency.

由于网络浏览器及其实现,缓存已成为我们词汇的一部分,但是在本文中,让我们尝试超越外行的理解,并在我们的网站中实现缓存以提高效率。

As your site grows, you would realize that you need to change your strategy to manage all the new traffic you get — right from scaling up your servers to making sure you increase the efficiency along the way.

随着站点的增长,您将意识到需要改变策略来管理所获得的所有新流量-从扩展服务器到确保在整个过程中提高效率。

什么是缓存 (What Caching Is)

In the simplest of terms, a cache is a temporary storage, and caching is the process of storing data in a cache. How does that help a WordPress webmaster? Let’s break down the steps of what happens behind the scenes when a reader opens a page on your site.

用最简单的术语来说, 高速缓存是临时存储,而高速缓存是将数据存储在高速缓存中的过程。 这对WordPress网站管理员有什么帮助? 让我们分解一下读者打开您的网站页面时幕后发生的步骤。

Caching in websitesCaching in websites 网站缓存
[Source] [来源]

First, the browser sends a request to the URL on your site. Your web server responds to the request by making a few database queries to get information like title, body, and comments, and returns an HTML document. This HTML document is read by the browser and rendered as a page that you see — which is possible by downloading all the stylesheets, scripts and images associated with the HTML document.

首先,浏览器将请求发送到您网站上的URL。 您的Web服务器通过进行一些数据库查询来获取标题,正文和注释之类的信息,以响应该请求,并返回HTML文档。 该HTML文档被浏览器读取,并呈现为您看到的页面-这可以通过下载与HTML文档关联的所有样式表,脚本和图像来实现。

There’s a possibility of delay at each step in the process described above. Your web server may be down with too many requests, your database server may not be responding, the server which hosts other files like scripts and images may be unresponsive.

在上述过程中,每个步骤都有延迟的可能。 您的Web服务器可能因太多请求而停机,您的数据库服务器可能没有响应,承载其他文件(如脚本和图像)的服务器可能没有响应。

Caching helps remove some of these steps in between by creating copies of commonly requested items like database queries, images or whole pages. Caching is beneficial when you host content that doesn’t change much over time — such as a match report about the recent World Cup final. You can simply cache a version of the page which is rendered every time a user visits the link.

缓存通过创建常见请求项的副本(例如数据库查询,图像或整个页面)来帮助消除其中的某些步骤。 如果您托管的内容不会随时间变化太多(例如有关最近的世界杯决赛的比赛报告),则缓存非常有用。 您可以简单地缓存每次用户访问链接时呈现的页面版本。

我“足够大”需要缓存吗? (Am I “Big” Enough to Need Caching?)

As evident from this discussion on Stack Exchange, there’s no pre-set limit of how “big” you need to be to enable caching. Although complex sites need it more, extra speed through better efficiency is always welcome — leaving you with happier readers and a lower bill.

对Stack Exchange的讨论中可以明显看出,启用缓存需要多大的预设限制。 尽管复杂的站点需要的更多,但始终欢迎通过提高效率来提高速度-使您拥有更快乐的读者和更低的费用。

Various studies have shown that an increase in load times leads to users abandoning the page. For instance, a half-second delay could lead to 20% less traffic, and drop of a second in load times for Amazon could lead to loss of $1.6 billion revenue in a year. Google even uses load times as an important parameter to determine the ranking of websites.

各种研究表明,加载时间的增加导致用户放弃该页面。 例如, 半秒的延迟可能导致流量 减少 20% ,而亚马逊的加载时间减少一秒可能导致一年内损失16亿美元的收入 。 Google甚至使用加载时间作为确定网站排名的重要参数

In short, one must always be on the lookout to improve performance of their websites, and caching is a way to achieve this.

简而言之,必须时刻注意提高网站的性能,而缓存是实现这一目标的一种方法。

缓存类型 (Types of Caching)

Let’s understand the various types of caching before we implement them. Broadly speaking, caching techniques can be grouped into two — client-side and server-side caching.

在实现它们之前,让我们了解各种类型的缓存。 从广义上讲,缓存技术可以分为两种:客户端缓存和服务器端缓存。

客户端缓存 (Client-side Caching)

Remember the need to “clear the cache”? That’s caching done by the browser. The most common way of client-side caching is browser caching. A browser may store files related to a web page and render it without making a request. Depending on the user’s settings, the browser may store only static files (such as stylesheets, scripts and images) or even the web page as a whole.

还记得需要“清除缓存”吗? 这是由浏览器完成的缓存。 客户端缓存的最常见方式是浏览器缓存。 浏览器可能会存储与网页有关的文件并在不发出请求的情况下呈现它。 根据用户的设置,浏览器可能仅存储静态文件(例如样式表,脚本和图像),甚至整个页面都存储。

It’s worth noting that a client-side cache is built when a user first visits a website, and works on subsequent visits.

值得注意的是,客户端缓存是在用户首次访问网站时进行的,并在以后的访问中使用。

服务器端缓存 (Server-side Caching)

As the name suggests, server-side caching is any caching that’s initiated on the server. Two common types of server-side caching are as follows:

顾名思义, 服务器端缓存是在服务器上启动的任何缓存。 两种常见的服务器端缓存类型如下:

  • Database Cache: Common queries like the list of posts to be shown in the home page of a site can be cached and the corresponding database queries can be avoided to achieve improvement in performance

    数据库缓存 :可以缓存常见查询,例如网站首页中显示的帖子列表,并且可以避免使用相应的数据库查询来提高性能

  • Page Cache: A server may cache the full HTML response to a request

    页面缓存 :服务器可以缓存对请求的完整HTML响应

  • Opcode Cache: PHP code may be compiled and saved after a request, which avoids the need to process the same file in subsequent requests.

    操作码缓存 :可以在请求后编译并保存PHP代码,从而避免了在后续请求中处理相同文件的需要。

Unlike client-side caching, a cache on the server can be built when content is created or edited. Therefore, even when a reader is visiting a site for the first time, a server cache might be in use, which leads to lower load times.

与客户端缓存不同,可以在创建或编辑内容时在服务器上建立缓存。 因此,即使读者是第一次访问站点,也可能正在使用服务器缓存,这会减少加载时间。

探索类似缓存的优化技术 (Explore Caching-like Optimization Techniques)

There are many techniques associated with caching that are often bundled with caching plugins, but which you can achieve independently too. We’ll discuss a few of these techniques here.

与缓存相关的许多技术通常与缓存插件捆绑在一起,但是您也可以独立实现。 我们将在这里讨论其中的一些技术。

HTTP压缩 (HTTP Compression)

The response sent by the server to the browser is a simple text file. The server may compress this text before sending it, thereby bringing down the size of the content to be sent. This saves bandwidth, and therefore brings down costs. Some plugins may use the term GZIP compression for HTTP compression.

服务器发送到浏览器的响应是一个简单的文本文件。 服务器可以在发送之前压缩该文本,从而减小要发送的内容的大小。 这节省了带宽,因此降低了成本。 一些插件可能将术语GZIP压缩用于HTTP压缩。

CDN的使用 (Use of CDNs)

Content delivery networks (CDNs) work under the premise that a server that is geographically closer to a client serves information in lesser time. A CDN refers to a network of servers distributed across the globe which decides which server to use depending on the location of the client. If you host your static files such as images on CDNs, it rests on most of the servers of the CDN and the server closest to your reader is selected to render the file.

内容交付网络 (CDN)的前提是,地理位置更接近客户端的服务器可以在更短的时间内提供信息。 CDN是指遍布全球的服务器网络,它根据客户端的位置来决定使用哪个服务器。 如果您将静态文件(例如图像)托管在CDN上,则它将驻留在CDN的大多数服务器上,并且选择了离您的阅读器最近的服务器来呈现文件。

缩小 (Minification)

Every stylesheet, script or image is loaded through a separate request to the server. The greater the size of these files and the number of requests, the longer time it takes to render the page. Minification is a technique that removes all unnecessary characters from your source code (like whitespaces) and makes the size of the file smaller. As a next step, certain plugins also combine all similar files into one to bring down the number of HTTP requests.

每个样式表,脚本或图像都通过单独的请求加载到服务器。 这些文件的大小和请求数越大,呈现页面所花费的时间越长。 缩小是一种技术,可从源代码中删除所有不必要的字符(例如空格),并使文件更小。 下一步,某些插件还将所有相似的文件合并为一个,以减少HTTP请求的数量。

图像优化 (Image Optimization)

Yet another technique to improve your page performance is reformatting images for the Web. Before using them on your pages, you can compress and resize images to bring down the file size.

改善页面性能的另一种技术是为Web重新格式化图像。 在页面上使用它们之前,您可以压缩图像并调整大小以减小文件大小。

Let’s now explore three of the most popular caching plugins in WordPress.

现在,让我们探索WordPress中三个最受欢迎的缓存插件。

WordPress中的缓存插件 (Caching Plugins in WordPress)

彗星缓存 (Comet Cache)

Comet Cache banner

Comet Cache, a popular plugin, provides a one-click feature to enable caching. Selecting this feature is sufficient for most websites. In addition to that, Comet Cache provides advanced features like cache clearing on modification of content, the ability to set a manual expiration time, trigger client-side caching and optimization the web server by modifying the .htaccess file.

Comet Cache,一个流行的插件,提供了一键式功能来启用缓存。 选择此功能对于大多数网站而言已足够。 除此之外,Comet Cache还提供高级功能,例如在修改内容时清除缓存,设置手动到期时间,触发客户端缓存以及通过修改.htaccess文件来优化Web服务器的功能。

If you’re just getting started with caching, Comet Cache is a good option.

如果您只是开始缓存,Comet Cache是​​一个不错的选择。

WP超级缓存 (WP Super Cache)

WP super cache banner

Automattic, the owner of WordPress.com, is the creator of WP Super Cache. The plugin has a well-defined options page, aptly grouped into buckets that make sense to anyone who’s familiar with the types of caching mentioned earlier.

WordPress.com的所有者Automattic是WP Super Cache的创建者。 该插件有一个定义明确的选项页面,该页面适当地分为多个存储桶,这对熟悉前面提到的缓存类型的任何人都有意义。

WP Super Cache Settings Page on WP AdminWP Super Cache Settings Page on WP Admin WP Admin上的WP超级缓存设置页面

WP Super Cache provides a single-click enable button with default settings too, and also provides CDN support.

WP Super Cache也提供具有默认设置的单击启用按钮,并且还提供CDN支持。

In its selection of advanced settings, you can select a delivery method for the caching, support for mobile caching and change the cache location. It also provides you with a debug mode through cache logs.

在其高级设置选择中,您可以选择一种缓存传递方式,支持移动缓存并更改缓存位置。 它还通过高速缓存日志为您提供调试模式。

W3总缓存 (W3 Total Cache)

W3 Total Cache

W3 Total Cache is one of the most popular caching plugins for WordPress, catering to beginners and experienced webmasters alike. In addition to features that we’ve already discussed, you can do much more with this plugin:

W3 Total Cache是​​WordPress最受欢迎的缓存插件之一,可同时满足初学者和经验丰富的网站管理员。 除了我们已经讨论过的功能之外,您还可以使用此插件做更多的事情:

  • Options for caching at page, database, object and browser levels.

    在页面,数据库,对象和浏览器级别进行缓存的选项。
  • Minify your static files in order to reduce their size

    缩小您的静态文件以减小其大小
  • Import and Export settings, beneficial during migration.

    导入和导出设置,在迁移期间很有用。

Therefore, W3 Total Cache is a one-stop solution for someone looking for a comprehensive solution.

因此,W3 Total Cache是​​寻求全面解决方案的人的一站式解决方案。

最后的想法 (Final Thoughts)

There are many caching plugins in the market, and we’ve only showed you a handful of them. Have you given them a try? Do you use a different plugin? Let us know in the comments!

市场上有很多缓存插件,我们只向您展示了其中的少数几个。 你试过了吗? 您是否使用其他插件? 让我们在评论中知道!

翻译自: https://www.sitepoint.com/wordpress-caching-guide/

wordpress打开缓存

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值