Forum Moderators: open

Message Too Old, No Replies

Any reason to comment out doctype?

Is the developer nuts, or am I missing something?

         

prfb

5:15 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



I was reviewing a certain site, looking at "view source" in Firefox and noticed that the first line of every page is...

<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -->

I understand the purpose of the "<!DOCTYPE" declaration, but I don't understand why it's preceded by "<!-- ". That comments it out, no?

Is there any good reason for that, or is it effectively just creating a page with no declared doctype?

For context: This is a brand new site, developed in Drupal (5.6). The site has a custom theme, and I believe what's setting this behavior is the page.tpl.php

Thanks,
P

coopster

5:30 pm on Jan 14, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, it is commented out. It may be perhaps because the developer has scrambled Strict with Transitional and didn't realize it!

prfb

6:20 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



Wow, that is nuts. So potentially the developer messed up the strict / transitional thing, and then couldn't figure out why the page didn't look right, so just commented out the whole declaration.

Coopster, thank you!

g1smd

12:46 am on Jan 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That's the sort of error that you could stare at for months without seeing it, especially if you had cut and pasted that code from some web tutorial somewhere...

rocknbil

3:04 am on Jan 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Commenting it out puts the page in quirks mode, which allows some non-standard coding to work that won't work under a valid doctype.

prfb

6:22 am on Jan 15, 2008 (gmt 0)

10+ Year Member



rocknbil- Any reason a person would do this on purpose with a new site, or just if you have legacy code?
Thanks,
P

rocknbil

5:08 pm on Jan 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, when I first started coding to standards, I noticed some things stopped working as soon as I added a valid doctype. My favorite simple example is color (there are many more.) In quirks mode,

.some_element { color: ff0000; }

works fine but as soon as you use a valid doctype you need

.some_element { color: #ff0000; }

Because #ff0000 is a valid color specification in standards mode, ff0000 is not.

So until I had time to fully understand coding to standards, I left the documents in quirks mode.

The problem then becomes hacking up the code and style sheets to get all browsers to play along. :-)

So most often I would guess it's because the developer doesn't understand why a valid doctype messes up their layout.