|
Post by account_disabled on Dec 13, 2023 9:24:40 GMT 1
快 WordPress 网站速度的最简单方法是删除所有不需要的资源。加快速度的第二个最简单的方法是压缩所有所需的资源。在 Web 服务器上启用 GZIP 压缩是实现此目标的最简单且最有效的方法之一。 所有现代浏览器默认都支持 GZIP 压缩。但是,为了顺利地向用户提供压缩资源,您需要正确配置服务器。 在这篇文章中,您将了解网络数据压缩的基础知识、什么是 GZIP 压缩、它的优点,以及如何使用它来加速不同服务器配置上的 WordPress 网站。 你等不及了吗?让我们开始减压吧! 您更喜欢观看视频版本吗? Web 上数据压缩的基础知识 压缩网络数据意味着减少网站传输的数据大小。根据数据类型(文本、图像、样式表、脚本、字体),有不同的方法来执行此压缩过程。 网页的主要组成部分 网页的主要组成部分 例如,缩小 HTML、CSS 和 JavaScript是减少浏览器发送的数据量的简单方法。在这里,压缩器通过从源代码中删除不必要的字符(例如注释和空格)来压缩文本。 在下面的示例中,我们考虑一个简单的HTML 文档,其中包含三种类 电话号码清单 型的内容:HTML 标记、CSS 样式和 JavaScript 代码。 每种内容类型都有独特的语法和语义。总的来说,这个 HTML 文档共有 357 个字符。 上面的代码很容易阅读和理解。它非常适合开发。然而,浏览器不需要阅读代码注释或看到完美缩进的标签。智能压缩器可以分析该文档并删除所有不必要的位。 缩小后,HTML 文档减少到只有 141 个字符。这节省了 60.50%的字符数。这并不容易看到,但这对浏览器来说并不重要。用户仍然会看到相同的页面。 要利用这两个版本,您可以将原始文档保留为“开发版本”,但在发布之前缩小所有代码。 大多数WordPress 性能优化插件会自动处理此问题。 未压缩与缩小的 jQuery 文件大小压缩 未压缩与缩小的 jQuery 文件大小压缩 如示例中所示,jQuery 3.5.1库的未压缩版本比同一文件的缩小版本大 3 倍。 同样,上述相同的压缩技术可以优化其他类型的内容,例如图像、视频、字体等。 像这样针对特定内容的缩减是优化网站文本资源大小的第一步。 这些明显的好处是 Kinsta在MyKinsta 仪表板中引入代码精简功能的原因。客户可以选择为其 CSS 和 JavaScript 文件启用自动代码压缩,从而轻松加快网站速度。 但数据压缩不仅仅是缩小。使用先进的数学技术,数据压缩算法可以进一步减小数据的大小。 这种数据压缩方法最流行的例子之一是GZIP。GZIP 可实现高效的数据传输,并为使互联网成为可行的全球通信媒介做出了重大贡献。 什么是 GZIP 压缩? GZIP 是GNU Zip的缩写,是网络上最流行的无损数据压缩方法。它允许您减小站点的 HTML 页面、样式表和脚本的大小。 GZIP 除了是一种数据压缩算法之外,还是一种文件扩展名 和用于压缩/解压缩文件的软件。 它基于DEFLATE 算法,该算法是LZ77 编码和Huffman 编码算法的混合。 GZIP压缩基于DEFLATE算法 GZIP压缩基于DEFLATE算法 GZIP 压缩器获取一批原始数据并对其进行无损压缩。原始数据可以来自任何文件类型,但 GZIP 最适合基于文本的资源(例如 HTML、CSS、JS)。 在下一节中,我们将深入了解 GZIP 压缩的工作原理。
|
|