Re: compact html on the fly

From: Date: Wed, 02 Aug 2000 14:46:05 +0000
Subject: Re: compact html on the fly
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-9703@lists.php.net to get a copy of this message
Daniel Convissor wrote: > > Hi Eric > > Eric Wood wrote: > > > > For example, Netscape may render these pages differently: > > > > <html> > > <head> > > Test > > </head> > > <body> > > test > > </body> > > </html> > > > > <html><head>Test</head><body>test</body></html> > > Netscape doesn't render those differently. For example, try this: > > <body>Sample text<p>some par text</p></body> > > Then change it to this > > <body> > <p> Sample text </p> > <p> some par text </p> > </body> > > and reload. > > No change at all in how it looks. > > > However, is there a way PHP or Apache can compact the page as it is being > > served? > > Sure, but is it worth it? Not really. Well, this might depend on someone's bandwidth. If you use output buffering with php4, you can save a lot of bandwidth (which costs more than the extra CPU power to do this) by doing this: (1) buffer output (2) since a browser is supposed to ignore white space, you could get away with stripping it, e.g., $buffer = preg_replace("/\w+/", " ", $buffer); (or something like that; you actually would have to write a somewhat more complex one so you don't strip white space inside a <PRE> tag) (3) if the browser supports it, compress, e.g., $buffer = gzcompress($buffer) (this, BTW, can be a huge savings, converting a 100K HTML document to 10K, which means you can serve 10 times the web pages on the same bandwidth as almost all browser support this now) (4) print the buffer Ciao, Andreas

« previous php.general (#9703) next »