我收到了谷歌速度测试的消息:
使用gzip压缩以下资源可以将传输大小减少67.4KiB(减少65%)。
Compressing http://localhost/english/jquery.js could save 57.9KiB (65% reduction).
Compressing http://localhost/english/javascript/slider.js could save 4.8KiB (71% reduction).
Compressing http://localhost/english/style/style.css could save 3.7KiB (72% reduction).
Compressing http://localhost/english/javascript/home.js could save 1.0KiB (64% reduction).
我该怎么办?
答案 0 :(得分:4)
在您的网络服务器配置中,您应该启用模块/扩展程序,以压缩发送到浏览器的文本(css,js,html,...)内容。
通常,如果您使用的是Apache网络服务器,则必须启用并配置mod_deflate
。
作为旁注:您将在Web服务器配置中执行此操作 - 激活压缩与PHP 无关(CSS / JS由运行PHP脚本的同一Apache服务器提供,但这些都是共同的)
答案 1 :(得分:0)
将mod_deflate安装到您的服务器&启用它
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
</IfModule>
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 text/javascript
AddOutputFilterByType DEFLATE application/x-javascript
<Files *.html>
SetOutputFilter DEFLATE
</Files>
<Files *.php>
SetOutputFilter DEFLATE
</Files>
ExpiresActive On
ExpiresDefault "access plus 4 weeks"
ExpiresByType image/gif "modification plus 5 hours 3 minutes"
ExpiresByType image/png "modification plus 5 hours 3 minutes"
ExpiresByType image/jpg "modification plus 5 hours 3 minutes"
ExpiresByType image/jpeg "modification plus 5 hours 3 minutes"
答案 2 :(得分:0)
您可以在服务器上使用mod_deflate
。
<IfModule mod_deflate.c>
# compress by mime type
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
# compress certain file / file type
<Files *.html>
SetOutputFilter DEFLATE
</Files>
</IfModule>