Apache turns on GZIP to compress web pages_PHP tutorial

WBOY
Release: 2016-07-20 11:13:31
Original
736 people have browsed it

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>
Copy after login

(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&rsquo;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>
Copy after login

(2)Filter file types

# mod_deflate:

<span <</span><span ifmodule </span><span mod_deflate.c</span><span ></span><span 

DeflateCompressionLevel 6

SetOutputFilter DEFLATE    #压缩所有文件

#Don&rsquo;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>
Copy after login

5. Effect

Gzip compression not enabled:

Enable Gzip compression:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440350.htmlTechArticle2. 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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template