duanpo7796
2014-08-26 06:33
浏览 102
已采纳

在HTML文档中写什么来启用GZip?

I have added the following code in my website to enable GZIP Compression, but still when i am testing my webpage its giving me following error message on an online GTCompression testing website . Kindly tell me is it anything i need to add in my HTML file as well?

Web Page        The http server hasn't sent out a "Content-Encoding" header.
Your Browser    Your browser is accepting compressed content.

.htaccess FIle

    <ifModule mod_gzip.c>
         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 mime ^image/.*
         mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
         </ifModule>

图片转代码服务由CSDN问答提供 功能建议

我在我的网站上添加了以下代码以启用 GZIP 压缩,但仍然在 我正在测试我的网页,它在线GTCompression测试网站上给出了以下错误消息。 请告诉我,我需要在HTML文件中添加任何内容吗?

 网页http服务器尚未发送“Content-Encoding”标题。 您的浏览器您的浏览器正在接受压缩内容。
   
 
 

.htaccess FIle

   &lt; ifModule mod_gzip.c&gt; 
 mod_gzip_on是
 mod_gzip_dechunk是
 mod_gzip_item_include文件。(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 mime ^ image /.* 
 mod_gzip_item_exclude rspheader ^ Content-Encoding:。* gzip。* 
&lt; / ifModule&gt; 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongxing2015 2014-08-26 06:55
    已采纳

    You will need to add the following lines to your .htaccess file:

    <IfModule mod_deflate.c>
      # Compress HTML, CSS, JavaScript, Text, XML and fonts
      AddOutputFilterByType DEFLATE application/javascript
      AddOutputFilterByType DEFLATE application/rss+xml
      AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
      AddOutputFilterByType DEFLATE application/x-font
      AddOutputFilterByType DEFLATE application/x-font-opentype
      AddOutputFilterByType DEFLATE application/x-font-otf
      AddOutputFilterByType DEFLATE application/x-font-truetype
      AddOutputFilterByType DEFLATE application/x-font-ttf
      AddOutputFilterByType DEFLATE application/x-javascript
      AddOutputFilterByType DEFLATE application/xhtml+xml
      AddOutputFilterByType DEFLATE application/xml
      AddOutputFilterByType DEFLATE font/opentype
      AddOutputFilterByType DEFLATE font/otf
      AddOutputFilterByType DEFLATE font/ttf
      AddOutputFilterByType DEFLATE image/svg+xml
      AddOutputFilterByType DEFLATE image/x-icon
      AddOutputFilterByType DEFLATE text/css
      AddOutputFilterByType DEFLATE text/html
      AddOutputFilterByType DEFLATE text/javascript
      AddOutputFilterByType DEFLATE text/plain
      AddOutputFilterByType DEFLATE text/xml
    
      # Remove browser bugs (only needed for really old browsers)
      BrowserMatch ^Mozilla/4 gzip-only-text/html
      BrowserMatch ^Mozilla/4\.0[678] no-gzip
      BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
      Header append Vary User-Agent
    </IfModule>
    
    点赞 打赏 评论
  • douwei4370 2014-08-26 06:38

    Try below code

    <IfModule mod_deflate.c>
              # force deflate for mangled headers
              # developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
              <IfModule mod_setenvif.c>
                <IfModule mod_headers.c>
                  SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
                  RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
                </IfModule>
              </IfModule>
    
              # HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
              <IfModule filter_module>
                FilterDeclare   COMPRESS
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/html
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/css
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/plain
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/xml
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/x-component
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/javascript
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/json
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xml
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xhtml+xml
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/rss+xml
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/atom+xml
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/vnd.ms-fontobject
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $image/svg+xml
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/x-font-ttf
                FilterProvider  COMPRESS  DEFLATE resp=Content-Type $font/opentype
                FilterChain     COMPRESS
                FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
              </IfModule>
    
              <IfModule !mod_filter.c>
                # Legacy versions of Apache
                AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
                AddOutputFilterByType DEFLATE application/javascript
                AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
                AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml 
                AddOutputFilterByType DEFLATE application/atom+xml
                AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject 
                AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype
              </IfModule>
            </IfModule>
    
    点赞 打赏 评论

相关推荐 更多相似问题