Home > Article > Backend Development > Apache turns on GZIP to compress web pages_PHP tutorial
2. Web server processing
By looking at the HTTP header, we can quickly determine whether the client browser used supports gzip compression.
If the following information appears in the sent HTTP header, it means that your browser supports the corresponding gzip compression:
# mod_gzip
<span <</span><span ifModule </span><span mod_gzip.c</span><span ></span><span mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </span><span <</span><span ifModule</span><span ></span>
(1) Strictly match file types
# mod_deflate:
<span <</span><span ifmodule </span><span mod_deflate.c</span><span ></span><span DeflateCompressionLevel 6 #压缩率, 6是建议值. AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/php AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/atom_xml AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/x-httpd-php AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE image/gif image/png image/jpe image/swf image/jpeg image/bmp # Don’t compress images and other #排除不需要压缩的文件 BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html SetEnvIfNoCase Request_URI .(?:html|htm)$ no-gzip dont-varySetEnvIfNoCase #SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary SetEnvIfNoCase Request_URI .(?:pdf|doc)$ no-gzip dont-vary </span><span </</span><span ifmodule</span><span ></span>
(2)Filter file types
# mod_deflate:
<span <</span><span ifmodule </span><span mod_deflate.c</span><span ></span><span DeflateCompressionLevel 6 SetOutputFilter DEFLATE #压缩所有文件 #Don’t compress images and other #过滤不需要压缩文件 #SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI .(?:html|htm)$ no-gzip dont-vary SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary SetEnvIfNoCase Request_URI .(?:pdf|doc)$ no-gzip dont-vary </span><span </</span><span IfModule</span><span ></span>
5. Effect
Gzip compression not enabled:
Enable Gzip compression: