我已经在服务器上启用了 mod_deflate。问题是 Google pagespeed 说我的网站需要压缩。
有人有主意吗?
此代码位于 /etc/apache2/apache2.conf 中。我重新启动了 apache。
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain text/html text/xml
AddOutputFilterByType DEFLATE text/css text/javascript
AddOutputFilterByType DEFLATE text/js text/javascript
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript application/x-
javascript
</IfModule>
答案1
您忘记配置输出过滤器
SetOutputFilter DEFLATE
这是我用来在 Google Pagespeedinsight 上获得 100% 的 Mod_deflate 配置
# MOD_DEFLATE COMPRESSION
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript application/x-httpd-php
# SET VAR
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
# DEFLATE NOT COMPATIBLE BROWERS
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
更改完成后,不要忘记重新启动 Apache 服务