Yes, we can write views, partial views or widgets so that they will produce a piece of HTML output that has a clean indentation. Some tools have clever functions to help us do it.
But once you have implanted a partial view or a widget in a view, and put the content view into the layout view, it’s impossible to maintain a clean indentation in the HTML output as a whole.
I once had a chance to read a code trying to produce a well indented HTML output as a whole.
In it, the HTML fragment codes had lengthy leading spaces so that they could fit well into the main code. And some utility subroutines had a parameter named ‘indent_depth’ in order to change the leading spaces. And what you’ve got after all is a set of source codes that are very hard to read and maintain.
Voted for #2. It’ll just leave me with the feeling of having written clean and reproducable code. As for the finalö output: I gave up on that a long time ago. If I generate (X)HTML via XSL/T, I tend to strip unimportant whitespaces alltogether. Pages compress a bit better that way.
Well I said gzip because I voted for max indentation, so that gives lots of useless spaces for the browser’s interpretation.
gzip (any?) compression algorithm should be effective because we’re talking about HTML (text) files.
My home page with very good HTML/CSS separation weighs 18,534 bytes for the HTML alone (230 lines). It’s gzipped to 5,256 bytes. With no indentation at all, the same HTML weighs 14,682 bytes. When gzipped, it’s 5,039 bytes.
See my point? 200 bytes are imho worth the indentation. And I’m not even using mod_deflate because I don’t have it on my shared host.
Now, according to my experience, sometimes proper HTML output indentation is necessary because a closing tag is possible to miss, and browser interpretations can vary, especially prior to HTML5 (which introduces optional closing tags by design). And Safari inspector (the one I use most for HTML) show only beautified/indented and even closed-tag HTML code, so it’s not the exact copy of the source. I think I remember FF has the same behavior… but maybe I’m wrong.
Yes, we sometimes have to examine the raw html output to debug. The raw html can have errors like missing opening/closing tags or overlapping tags. But those errors will be covered up by the browsers’ parser, and we will see only the corrected DOM tree.
So I admit that cleanly formatted raw html output has some advantage. But it is very small and not worth the effort. We can use our favorite editor to check the matching of tags, and it doesn’t matter how beautiful the html is indented when we do that kind of debugging.
anyways why indent the html output code? hahaha is there any good man can perfectly indent a html code after it is produced by server-side code to the client-side?