|
|
Compressing HTML output with PHP
A site I work recently had its hosting upgraded and pages that were previously 45K (ish) are now between 3K and 8K. This made me curious as to why. Upon inspection I found that you can compress HTML pages on the fly.
This is new to me so thought I'd share: http://uk.php.net/manual/en/function.ob-gzhandler.php one line of code, and ta da 80% smaller file size. If the browser can't handle it, it just supplies the normal page. v cool - If you're feeling brave you could modify the ini file to do the zlib thing. Being as the site isn't hosted on my mac I haven't done that 'cause I like to see how large the html output is. |
|
VERY nice tip. Gracias!
|
Is this supposed to be added before the doctype even? And how can we test if it actually is working?
|
Compression (mod_deflate on Apache 2.0.54 runing off of a g4 sawtooth under my desk) knocked my pages down bt 74%. Awesome. |
Code:
//However as other people have pointed out, its better to get the server software to do it. To test if its working: access the page in Safari without the compression on and view the activity window - you can get the file sizes. Then turn compression off and try it. If it is working you should see a marked decrease in the file size for the main html document. If you look here: http://moodymonster.com/mgfs/index.php the main index file is ~45K the compressed version: http://www.mobilegamefaqs.com/index.php index file ~9K Thats not using the PHP method though, its running through the server software but the principal is the same. Though I'd try it using the PHP method by pasting: ob_start("ob_gzhandler"); right at the top of the code, resulting file: http://moodymonster.com/mgfs/index_gz.php file size: ~9K |
| All times are GMT -5. The time now is 11:43 PM. |
|
Copyright © 2005-2007 MacNN. All rights reserved.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.