You are here: Re: compress html output with php? « PHP Programming Language « IT news, forums, messages
Re: compress html output with php?

Posted by Toby A Inkster on 03/23/07 13:49

Richard Formby wrote:

> Does anyone know if it's worth it? [compressing HTML] I mean is the time
> spent running the function less then the time it would take to download
> the longer html file? Any thoughts on this?

Not the way Ciaran's attempting to do it. Gzipping HTML as you send it
will lead to a dramatic reduction in file size. (The resultant file will
probably be half the size of the original, or even smaller.) Whatsmore,
the compression is done in well-optimised C code, so it uses very little
time to do. You can perform it using particular settings in php.ini or
Apache, so it doesn't require any modification to your PHP code base,
making it very easy to toggle on or off as required.

Stripping out redundant whitespace in a file leads to a small reduction in
file size. Depending on how much whitespace there is in the first place,
you might shave off 10% or so from the file size. The compression is
typically done using PHP and regular expressions, which is slower than the
method above. It generally requires you to make some modifications to your
PHP code. Whatsmore, it's error-prone. Whitespace is significant in some
places (e.g. within PRE, TEXTAREA and SCRIPT elements). Most whitespace
stripping scripts get this wrong in certain places -- getting it right
requires even more careful effort parsing the HTML, and slows the script
down even more.

Zipping HTML content in transit can save significant bandwidth on
mainly textual websites without using much extra CPU time.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация