PHP Enable Compressing GZIP
I have this message开发者_运维百科 from google speed test:
Compressing the following resources with gzip could reduce their transfer size by 67.4KiB (65% reduction).
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).
What should I do?
In the configuration of your webserver, you should enable the module/extension that will compress text (css, js, html, ...) content that's sent to the browsers.
Typically, if you are using the Apache webserver, you'll have to enable and configure mod_deflate
.
As a sidenote : you will do this in the webserver configuration -- activating compression has pretty much nothing to do with PHP (CSS/JS are served from the same Apache server that runs PHP scripts, but that's all there is in common).
Install mod_deflate to your server & enable it
<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"
You can use mod_deflate
on server.
<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>
精彩评论