2

Possible Duplicate:
How to minify php page html output?
Any reason not to strip whitespace in HTML

I viewed some page sources and found some difference between them - some with indents some doesn't. The first screen capture is google's page source, and the second SO's.

I want to know whether eliminating those spaces improve page loading speed or it means smaller data flow from server to client. If doing so is meaningful, how do i do it before output data from server(I use PHP).

Without spaces-Google's page source: Google's page source capture

With spaces-SO's page source: enter image description here

Community
  • 1
  • 1
dotslashlu
  • 3,361
  • 4
  • 29
  • 56
  • @SergeiTulentsev Is doing this meaningful and how to do this. – dotslashlu Dec 30 '11 at 15:47
  • 4
    Guys, why the close votes? I think the OP asks a legal question here. – orlp Dec 30 '11 at 15:49
  • possible duplicate of [Any reason not to strip whitespace in HTML](http://stackoverflow.com/questions/7115217/any-reason-not-to-strip-whitespace-in-html) -and- [MSO: Unnecessary trailing whitespace in HTML source for Stack Overflow?](http://meta.stackexchange.com/questions/15394/unnecessary-trailing-whitespace-in-html-source-for-stack-overflow) – mario Dec 30 '11 at 15:59

4 Answers4

3

This is called "minification". Most of the savings are in the bandwidth of not needing to transmit all of the extra whitespace, etc. - though even this is minimal overhead if GZip compression is used (transparently supported by all major web browsers and web servers). There may also be very slight performance savings in the browser not needing to parse through the additional whitespace.

There are many libraries that can do this for you. http://code.google.com/p/minify/ is just one of them.

ziesemer
  • 27,712
  • 8
  • 86
  • 94
  • Dose google's developer write code without indents? That's horrible... I thought they has their way to eliminate spaces before output. – dotslashlu Dec 30 '11 at 15:54
  • 1
    @LotusH - I'm assuming that's a rhetorical question. No, Google certain does not write their code like that. They don't write the code at all. Their code writes itself. :-) – ziesemer Dec 30 '11 at 16:06
1

You're looking at minification here which uses techniques such as removal of whitespace and variable renaming to minimize the number of bytes transferred. However, the bottleneck is often not from delivering site content and you should first determine through profiling whether you really do need to optimise your page at all.

This is a tool for minifying HTML.

Mike Kwan
  • 24,123
  • 12
  • 63
  • 96
1

Trimming excess whitespace could marginally reduce down the size of a page but the savings are likely to be small.

Likely Google's page source is machine generated or compiled into something more size-efficient. It's worth noting that a few bytes of saved data in a page might be insignificant to most of us but if you're serving the page millions of times a day then you'd save yourself [millions] * [bytes saved per page] bytes a day which could end up being significant if you're Google.

James C
  • 14,047
  • 1
  • 34
  • 43
0

Minifying everything possible is always a good idea when using limited bandwidth, reducing the amount of data sent over HTTP will most definitely decrease the load time!

Check this out: http://code.google.com/speed/page-speed/docs/payload.html#MinifyHTML

Korvin Szanto
  • 4,531
  • 4
  • 19
  • 49