HTML output + PHP strip-whitespace

Soldato
Joined
12 Jun 2005
Posts
5,361
Hi there,

I hear its best (& not detrimental) to strip whitespace from the outputted html to save bandwidth.

Most of my sites work on php and includes with footers and headers, etc....

What would be the best way to go about striping whitespace? Ideally i would like something that i can comment out for debugging purposes.

Does anyone do this? How did you go about doing this?

Thanks.
 
Surely you would have to buffer your entire script's output in order to strip the whitespace, giving the impression of a far slower load time?
 
if your pages are loading slower than they should its likely you need to look into database indexes or your coding methods rather than removing a few bytes from your output which will have little or no effect on loading times anyway :)
 
Its not that my pages are loading too slow, its just i thought i would try this to optimize for bandwidth saving.

At the moment my pages are all perfectly tabbed and look like a piece of art when you view the source, which is a bit stupid because it's useless, other than for debugging.

Surely you would have to buffer your entire script's output in order to strip the whitespace, giving the impression of a far slower load time?

See - this is what i was afraid of, i was just wondering if anyone has actually done this and can say how it went...etc....
 
What I'd do is the following:

Continue to tab out your code on your development machine.
Run a copy of it through a script to remove the whitespace.
Upload this stripped version to the server.

This means you'll always have your nicely tabbed version ready for adjustments, without having to sift through a solid block of text! ;)
 
What I'd do is the following:

Continue to tab out your code on your development machine.
Run a copy of it through a script to remove the whitespace.
Upload this stripped version to the server.

This means you'll always have your nicely tabbed version ready for adjustments, without having to sift through a solid block of text! ;)

Good idea, don't get me wrong - but is there a sophisticated enough code which will strip whitespace in php pages that output html etc....
 
I think it's pretty pointless to be honest... whitespace will save a few bytes, but so what! Unless you're constantly at the edges of your bandwidth limit, you'd be much better off spending time improving current php scripts to use less CPU cycles, figuring out if there are faster ways to do things, etc.

Or even just compressing images more / differently is probably going to have a bigger effect than removing whitespace.

Just my two cents :p
 
Back
Top Bottom