Post by account_disabled on Dec 13, 2023 8:17:44 GMT
您的网站包含的 HTTP 请求越多,加载速度就越慢。通过减少 HTTP 请求的数量并优化其加载,您可以提高网站的性能。 在这篇文章中,我们将告诉您有关如何在 WordPress 中发出更少 HTTP 请求的所有信息。 我们将从 HTTP 请求的基本介绍开始,为什么它们很重要,以及如何分析 WordPress 网站的请求。 然后,我们将分享一些您可以实施的技巧和策略,以减少对您网站的需求。除了帮助您解决 GTmetrix 中的“减少 HTTP 请求”消息之外,这些策略还将帮助您解决 Google PageSpeed Insights 中的“避免链接关键请求”建议。 您更喜欢观看视频版本吗? 什么是 HTTP 请求? 建立网站时,有许多不同的部分需要考虑。页面上使用不同的图像文件、控制内容外观的CSS 样式表、添加所有这些炫酷功能的 JavaScript 文件等等。 当有人访问您的网站时,他们的浏览器需要一种从您的服务器下载该页面所需的所有资源的方法。为此,它向服务器发送每个单独资源的HTTP 请求。 例如,它可能会说,“嘿服务器,我需要文件”和“嘿服务器,我还需要该联系表单插件的 CSS 样式表”。服务器使用相关文件响应这些请求。
旦网络浏览器获取这些文件,它就可以为访问它的人组装网页。当然,它比这更复杂一些,但这就是 电话号码清单 基本思想。 HTTP 是超文本传输协议的缩写,是这些计算机(访问者的浏览器和网络服务器)进行通信的方式。 需要理解的一件重要的事情是,每个单独的元素都是一个单独的 HTTP 请求。例如,如果网页上有五个图像文件,则浏览器必须发出五个单独的 HTTP 请求,每个请求对应一个图像。 同样,如果您使用四个WordPress 插件,并且每个插件都添加自己的 CSS 样式表,则访问者的浏览器将必须发出四个单独的 HTTP 请求,每个请求对应一个插件样式表。 为什么减少 HTTP 请求很重要? 为什么减少 HTTP 请求很重要 一般来说,您的网站发出的 HTTP 请求越多,加载速度就越慢。因此,如果您希望网站加载速度更快,则需要优化并减少网站所需的 HTTP 请求数量。 虽然这有点过于简单化,但基本思想是,Web 浏览器仅在下载完所有 HTTP 请求后才会向访问者显示网站(尽管有一些策略可以告诉浏览器最好等待某些文件)。 因此,如果网站必须发出 70 个 HTTP 请求才能显示页面,则比发出 40 个 HTTP 请求所需的时间要长。
此外,某些 HTTP 请求会“阻止”其他 HTTP 请求,这意味着浏览器在完成下载之前的 HTTP 请求之前无法开始下载某些 HTTP 请求。 底线:通过减少 HTTP 请求的数量,可以使网站加载速度更快。 如何查看和分析站点的 HTTP 请求 目前,您已经了解到,在所有条件相同的情况下,减少 HTTP 请求的数量将提高您的网站速度。然而,HTTP 请求并不总是“相同”。某些 HTTP 请求比其他请求大。有些比其他慢。 例如,请求 3MB 的巨大图像文件将比请求 20KB 的小图像花费更长的时间。 如果您想对您的网站进行最大的改进,请首先关注大型且加载缓慢的 HTTP 请求,以便获得最大的投资回报。 要分析站点的 HTTP 请求,您可以使用称为瀑布分析的工具。 大多数速度测试工具都提供此功能,但GTMetrix和Pingdom的接口非常方便。您还可以使用浏览器的开发工具(“开发人员工具”功能)。在本文中,我们将使用 GTmetrix 进行屏幕截图。 一旦您指定了您的URL,您将在顶部看到一个包含基本信息的摘要框。这显示了您的网站有多少个 HTTP 请求,但不会细分各个请求: 测试网站的 gtmetrix 结果示例 要分析您的个人请求,请转到下面的“瀑布”选项卡。 在这里,您将看到网站上每个 HTTP 请求的列表以及有关该请求下载所需时间的信息: 来自 gtmetrix 的瀑布图示例 您可能会注意到并非所有 HTTP 请求都是相同的。
旦网络浏览器获取这些文件,它就可以为访问它的人组装网页。当然,它比这更复杂一些,但这就是 电话号码清单 基本思想。 HTTP 是超文本传输协议的缩写,是这些计算机(访问者的浏览器和网络服务器)进行通信的方式。 需要理解的一件重要的事情是,每个单独的元素都是一个单独的 HTTP 请求。例如,如果网页上有五个图像文件,则浏览器必须发出五个单独的 HTTP 请求,每个请求对应一个图像。 同样,如果您使用四个WordPress 插件,并且每个插件都添加自己的 CSS 样式表,则访问者的浏览器将必须发出四个单独的 HTTP 请求,每个请求对应一个插件样式表。 为什么减少 HTTP 请求很重要? 为什么减少 HTTP 请求很重要 一般来说,您的网站发出的 HTTP 请求越多,加载速度就越慢。因此,如果您希望网站加载速度更快,则需要优化并减少网站所需的 HTTP 请求数量。 虽然这有点过于简单化,但基本思想是,Web 浏览器仅在下载完所有 HTTP 请求后才会向访问者显示网站(尽管有一些策略可以告诉浏览器最好等待某些文件)。 因此,如果网站必须发出 70 个 HTTP 请求才能显示页面,则比发出 40 个 HTTP 请求所需的时间要长。
此外,某些 HTTP 请求会“阻止”其他 HTTP 请求,这意味着浏览器在完成下载之前的 HTTP 请求之前无法开始下载某些 HTTP 请求。 底线:通过减少 HTTP 请求的数量,可以使网站加载速度更快。 如何查看和分析站点的 HTTP 请求 目前,您已经了解到,在所有条件相同的情况下,减少 HTTP 请求的数量将提高您的网站速度。然而,HTTP 请求并不总是“相同”。某些 HTTP 请求比其他请求大。有些比其他慢。 例如,请求 3MB 的巨大图像文件将比请求 20KB 的小图像花费更长的时间。 如果您想对您的网站进行最大的改进,请首先关注大型且加载缓慢的 HTTP 请求,以便获得最大的投资回报。 要分析站点的 HTTP 请求,您可以使用称为瀑布分析的工具。 大多数速度测试工具都提供此功能,但GTMetrix和Pingdom的接口非常方便。您还可以使用浏览器的开发工具(“开发人员工具”功能)。在本文中,我们将使用 GTmetrix 进行屏幕截图。 一旦您指定了您的URL,您将在顶部看到一个包含基本信息的摘要框。这显示了您的网站有多少个 HTTP 请求,但不会细分各个请求: 测试网站的 gtmetrix 结果示例 要分析您的个人请求,请转到下面的“瀑布”选项卡。 在这里,您将看到网站上每个 HTTP 请求的列表以及有关该请求下载所需时间的信息: 来自 gtmetrix 的瀑布图示例 您可能会注意到并非所有 HTTP 请求都是相同的。