Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html code well formatted vs one line code

Tags:

html

web

I see more and more pages (eg. translate.google) where the html code is formatted in one line? Is it made to shorten the loading time? Is it the state of the art now?

Thanks

like image 471
Anatoliy Avatar asked Jan 18 '11 14:01

Anatoliy


2 Answers

HTML is for browsers. They don't need extra newlines/spaces people need.

If HTML is generated in a program, it needs extra time/code to format HTML readable for humans. So it is easier to output it in one line.

like image 73
eumiro Avatar answered Nov 03 '22 15:11

eumiro


The short answer is Yes: it reduces the size of the download.

Even if that doesn't have much impact on the download speed for the individual user, if the site is serving pages to a lot of users, then the cumulative effect is a significant reduction in the amount of traffic their server has to send.

It's pretty easy to strip the redundant white space out of a HTML document, so it would probably have been written with the white space in-tact during development, and then removed afterward when it was deployed to the live system.

You'll find that Javascript and CSS files are often given the same treatment as well.

As an end user, you shouldn't have any need to look at the raw HTML. If you really want to see how the page is written, don't look at the source, rather look at the DOM - ie the tree view of the elements in the HTML page (for visual purposes; the DOM is a lot more than this, but that's what you can see)

You can see this using Firefox's Firebug extension, or the Developer Tools feature in IE8, Chrome or Safari.

Hope that helps.

like image 44
Spudley Avatar answered Nov 03 '22 13:11

Spudley