Fog Creek Software
Discussion Board




html indentation

I notice that everyone seems to use there own way to indent html code.  For example: joelonsoftware.com seems to only indent tables, while most pages on microsoft.com seem to indent every nested tag.

What do other people use and why?

Jeff
Wednesday, March 26, 2003

I usually indent anything within a container tag, so it's easier to make out the hierarchy of the code. There's no particular reason I do it this way, I suppose, it just feels better to me to edit it that way.

Lach
Wednesday, March 26, 2003

I have tidy do indentation, and after I muck it up editing, I run it again to fix my formatting 8-}

Mike Swieton
Wednesday, March 26, 2003

If I weren't so lazy I'd keep two versions of my HTML files: a fully-indented one for editing, and then an automatically-generated one with all non-critical whitespace stripped out for publishing...

Dan Maas
Thursday, March 27, 2003

It's indented in development and then we have a "cleaner" utility that strips out unnecessary whitespace from HTML, JavaScript and CSS files that runs as part of the build (it also injects a copyright comment at the top of all). The cleaner is basically running a bunch of RegEx replacements as well as a bit of custom parsing stuff for the JavaScript.

Duncan Smart
Thursday, March 27, 2003

All our HTML is programatically generated. Flip a switch for indents. ;)

Brad (dotnetguy.techieswithcats.com)
Thursday, March 27, 2003

Do you really think white space slows down the browser's experience at all?

pb
Thursday, March 27, 2003

re: stripping out white space making a difference.

If you have large amounts of HTML, sometimes stripping white space can make a marginal difference in the download time.

We tend to strip out white space when we want to make it harder for people to figure out things from the HTML source.  If everything is a) auto-generated and b) all on one line - random copycats have to output more effort.

Or so goes the theory.

Phibian
Thursday, March 27, 2003

It depends on how busy your servers are, whether bandwidth is a bottleneck for you, and how large the HTML is that you're generating. In my experience, a "well indented" HTML file is generally going to be 10-15% whitespace (not scientific, just my small testing experience). This can make a rather substantial difference on large HTML, or when you're paying for metered access.

Like most optimizations, it has the potential to be a premature one.

Brad (dotnetguy.techieswithcats.com)
Thursday, March 27, 2003

Of course, if you use mod_gzip or similar, you really don't have to worry about  that tiny boost in filesize from indenting. As for hiding code from people, I don't see the point. If it's on the web it can be stolen. If you don't like that, then don't publish it.

Lach
Saturday, March 29, 2003

*  Recent Topics

*  Fog Creek Home