Post by account_disabled on Dec 10, 2023 10:14:45 GMT
它现在被标记为具有高效缓存策略的服务静态资产: 具有高效缓存策略建议的服务器静态资产 具有高效缓存策略建议的服务器静态资产 这个建议有几个层面需要我们去探讨。首先是“缓存”的含义。简而言之,这是一个浏览器保存其页面副本的过程,以便在将来访问时可以更快地加载它们。 WordPress 网站实现缓存的最常见方式是使用插件。WP Rocket 和W3 Total Cache是流行的选择。然而,一些托管提供商(包括我们 Kinsta)允许通过他们的服务器进行缓存。在安装缓存插件之前,请务必检查您的主机是否属于这种情况。 一旦为站点启用了缓存,您就可以担心此建议的第二部分,即缓存策略的“效率”。
浏览器会定期清除缓存,以使用新 加拿大数据库 副本刷新它们。 理想情况下,这个时间范围应该更高而不是更低。如果您每两个小时清除一次网站的浏览器缓存,那么首先就违背了使用此技术的目的。您可以使用Cache-Control和Expires headers优化缓存过期时间。 添加缓存控制标头 使用以下代码在 Nginx 中添加 Cache-Control 标头:您应该将其添加到您的服务器配置文件中。在上面的示例中,指定的文件类型设置为在 30 天后过期。 那些拥有 Apache 服务器的人应该在其.htaccess文件中使用此代码段:将此代码添加到#BEGIN WordPress之前或#END WordPress之后。在此示例中,缓存过期时间设置为 84,600 秒。
添加过期标头 缓存控制标头现在已成为标准。但是,有一些工具(包括 GTMetrix)仍然会检查Expires headers 。 您可以通过将以下内容添加到服务器块来向 Nginx 服务器添加过期标头: 同样,您需要在#BEGIN WordPress之前或#END WordPress之后添加此代码。 高效的 Google Analytics 缓存 具有讽刺意味的是,您可能添加到页面标题中以跟踪用户行为的 Google Analytics 脚本的缓存有效期仅为两个小时。这很可能是因为,如果平台进行更新,用户将能够快速访问更改。 该脚本将出现在使用有效的缓存策略建议提供静态资产部分中需要您注意的资源列表中。由于它由第三方拥有,因此您无法使用Cache-Control或Expires headers 更改过期时间。
浏览器会定期清除缓存,以使用新 加拿大数据库 副本刷新它们。 理想情况下,这个时间范围应该更高而不是更低。如果您每两个小时清除一次网站的浏览器缓存,那么首先就违背了使用此技术的目的。您可以使用Cache-Control和Expires headers优化缓存过期时间。 添加缓存控制标头 使用以下代码在 Nginx 中添加 Cache-Control 标头:您应该将其添加到您的服务器配置文件中。在上面的示例中,指定的文件类型设置为在 30 天后过期。 那些拥有 Apache 服务器的人应该在其.htaccess文件中使用此代码段:将此代码添加到#BEGIN WordPress之前或#END WordPress之后。在此示例中,缓存过期时间设置为 84,600 秒。
添加过期标头 缓存控制标头现在已成为标准。但是,有一些工具(包括 GTMetrix)仍然会检查Expires headers 。 您可以通过将以下内容添加到服务器块来向 Nginx 服务器添加过期标头: 同样,您需要在#BEGIN WordPress之前或#END WordPress之后添加此代码。 高效的 Google Analytics 缓存 具有讽刺意味的是,您可能添加到页面标题中以跟踪用户行为的 Google Analytics 脚本的缓存有效期仅为两个小时。这很可能是因为,如果平台进行更新,用户将能够快速访问更改。 该脚本将出现在使用有效的缓存策略建议提供静态资产部分中需要您注意的资源列表中。由于它由第三方拥有,因此您无法使用Cache-Control或Expires headers 更改过期时间。