Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Q108】gzip 的原理是什么,如何配置 #109

Open
shfshanyue opened this issue Dec 7, 2019 · 1 comment
Open

【Q108】gzip 的原理是什么,如何配置 #109

shfshanyue opened this issue Dec 7, 2019 · 1 comment
Labels

Comments

@shfshanyue
Copy link
Owner

No description provided.

@shfshanyue shfshanyue added the http label Dec 7, 2019
@shfshanyue shfshanyue changed the title 【Q108】gzip 的实现原理是什么 【Q108】gzip 的原理是什么 Dec 8, 2019
@shfshanyue
Copy link
Owner Author

shfshanyue commented Dec 8, 2019

一句话:gzip 的核心是 Deflate,而它使用了 LZ77 算法与 Huffman 编码来压缩文件,重复度越高的文件可压缩的空间就越大。

因此 gzip 用于 HTTP 文件传输中,比如 JS、CSS 等,但一般不会压缩图片。在 HTTP Response 报文中,用 Content-Encoding 指明使用 gzip 压缩,而以下响应头在大部分生产环境的响应报文中都可以看到!比如你现在立刻马上可以打开我的网站或者百度试一试。

# Request Header
Accept-Encoding: gzip, deflate, br

# Reponse Header
Content-Encoding: gzip

gzip 一般在反向代理那一层,如 nginx 进行处理,直接使用 C 语言编写,具有更好的性能。

nginx 开启 gzip: 配置可参考 gzip module

gzip on;

LZ77

Huffman

相关阅读

@shfshanyue shfshanyue changed the title 【Q108】gzip 的原理是什么 【Q108】gzip 的原理是什么,如何配置 Jul 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant