PHP GZIP more information
I use the plugin of google for firefox "speed test" and I have this error:
Enable compression
Compressing the following resources with gzip could red开发者_运维知识库uce their transfer size by 65.8KiB (65% reduction).Now.. I know nothing about this subject and I want to learn more about this subject.
This is related/connected to OB ( like ob_start ) or somthing like that?
I'll be gateful to get more information and tutorials about this subject.
If there are vidoe guides its even better.This is the full notice that I've got from Google Speed Test:
Compressing the following resources with gzip could reduce their transfer size by 65.8KiB (65% reduction).
Compressing http://localhost/english/jquery.js could save 57.3KiB (65% reduction).
Compressing http://localhost/english/javascript/slider.js could save 4.0KiB (69% reduction).
Compressing http://localhost/english/style/style.css could save 3.7KiB (72% reduction).
Compressing http://localhost/english/javascript/home.js could save 853B (62% reduction).
Take a look at ob_gzhandler
. They have a very straight-forward example too:
<?php
ob_start("ob_gzhandler");
?>
<html>
<body>
<p>This should be a compressed page.</p>
</html>
<body>
If the browser supports gzip, then this page will be compressed with gzip and sent compressed, after which the browser will decompress it and render it. The advantage of doing this is lowering the amount of bytes that need to be transferred.
Background
- Google website performance rules
- Yahoo's Best Practices for Speeding Up Your Web Site
Explanation
When you want to send a big file to your friend, you compress it using zip, rar, or other archiver like gzip to save some bytes and make it faster.
You may also do the same and compress HTML pages, JavaScript and CSS files.
Browsers do automatically handle content compressed by gzip (gzipped), assuming they get the properly compressed files with appropriate HTTP response headers.
Solutions
There are many options to serve gzipped content, e.g.
- Compress the files manually and set the proper HTTP headers to serve them (e.g. in
.htaccess
or PHP script) - Create the gzipped versions using script
- Use output handler to gzip output (
ob_gzhandler
orzlib.output-compression
) - Use Apache module to automatically serve gzipped component, see mod_deflate
- Use Google's page speed module
Next step
Your next step will be probably merging all those files into one, to minimize HTTP requests. There are many tools to do this automatically.
The traditional way was to use ob_gzhandler. The manual stipulates that using zlib.output-compression, a php.ini directive that globally enables compression is preferred nowadays.
精彩评论