【问题标题】:gzip compression not working on xamppgzip压缩不适用于xampp
【发布时间】:2014-03-23 14:49:42
【问题描述】:

由于某种原因,gzip 无法正常工作

我的 gzip 压缩脚本

<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>

我正在使用:----

XAMPP server.last time updated: 2 min before this question

注意:所有文件都是 .PHP 文件,并且 .HTACCESS 文件位于根文件夹中

我如何发现它没有被压缩:通过在 GOOGLE CHROME(开发者工具)中运行审核

【问题讨论】:

    标签: php .htaccess xampp gzip


    【解决方案1】:

    我打赌您的 xampp 安装不是很旧,而且您可能使用的是最新版本的 Apache。所以你应该使用mod_deflate

    mod_gzipApache 1.xmod_deflateApache 2.x

    您可以试试这个并根据需要进行自定义。

    <IfModule mod_deflate.c>
    <FilesMatch "\.(html|txt|css|js|php|pl)$">
    SetOutputFilter DEFLATE
    </FilesMatch>
    </IfModule>
    

    或者你也可以这样试试。

    # compress text, html, javascript, css, xml:
    
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE image/jpeg
    AddOutputFilterByType DEFLATE image/png
    AddOutputFilterByType DEFLATE image/gif
    
    #Custom Setting End.
    

    您可能还必须在 Apache 配置中启用它。因此,您将取消注释该行并重新启动 Apache。

    LoadModule deflate_module modules/mod_deflate.so
    

    您还可以在此处查看 gzip 信息。 http://developer.yahoo.com/performance/rules.html#gzip

    【讨论】:

    • 感谢我的网页大小,标记(字节)从 54,134 减少到 5,512 压缩% 89.8....够了吗?
    【解决方案2】:

    在 httpd.conf 上取消注释这一行

    • Lo​​adModule deflate_module modules/mod_deflate.so
    • Lo​​adModule filter_module modules/mod_filter.so

    【讨论】:

      猜你喜欢
      • 2016-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-12
      • 1970-01-01
      • 1970-01-01
      • 2018-07-15
      相关资源
      最近更新 更多