homepage Welcome to WebmasterWorld Guest from 54.204.73.126
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: not2easy

CSS Forum

    
whitespace before Doctype and Quirks Mode
SuzyUK

WebmasterWorld Senior Member suzyuk us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3623733 posted 4:58 pm on Apr 10, 2008 (gmt 0)

I was always under the impression that whitespace before the Doctype caused IE6 to go into "Quirks" mode, but on a test I did earlier I thought to check it for the first time in ages, it doesn't trigger quirks!

I did a bit of searching to try and find out why I thought that, and apparently I'm not the only one under that illusion, which makes me feel a little better, but was there or is there ever a time when whitespace is not whitespace?

i.e. can <php, <asp, other scripting languages send content, headers/charsets? that might generate a "hidden character" in that whitespace - like a BOM?

I did read that NN6/Moz had a problem with whitespace before the Doctype at one point and that FF maybe still does depending on how many "characters" of whitespace is involved, maybe that's where it came from or maybe it's just one of those best practice things that we got used to - or maybe it was just a particular IE6 build? (I did test on a standalone)

anyone shed any light?

 

swa66

WebmasterWorld Senior Member swa66 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3623733 posted 6:56 pm on Apr 10, 2008 (gmt 0)

Wondering how one can see if IE (per version if different) is in quirks mode without changing content to have something like an image and text to see how it lines up ?

If FF I use the webmaster toolbar: it displays it for every page you open (e.g. this one has the "~" to show the quirksmode.

But in a fresh istall of IE: I've no idea how to see it in an eyeblink.

I presume the <?xml..> header always puts IE in quirksmode.
Honestly I'll be headstrong against MSFT: they should fix, not all the rest of us, and they should fix their old browsers too, not create more junk!

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3623733 posted 7:33 pm on Apr 10, 2008 (gmt 0)

i.e. can <php, <asp, other scripting languages send content, headers/charsets? that might generate a "hidden character" in that whitespace - like a BOM?

Not certain where this is headed? RFC2616 states that there must be an empty line after the last of the header fields (a line with nothing preceding the CRLF) which indicates the end of the header fields. Everything after that is considered message body. Example below.

Develop a document with 20 <enter> keystrokes before any of your HTML including the DOCTYPE and save it to your server. Request that document and you will see the 20 blank lines when you view source on the document. When the user agent begins to render the document it determines where the header fields end and where the message body begins based on this specification, for HTTP/1.1 at least.

HTTP/1.x 200 OK 
Date: Thu, 10 Apr 2008 19:29:34 GMT
Server: Apache/4.0
Last-Modified: Thu, 10 Apr 2008 18:16:20 GMT
Etag: "200000002c858-351d-44a88d07fdc01"
Accept-Ranges: bytes
Content-Length: 13597
Keep-Alive: timeout=5, max=95
Connection: Keep-Alive
Content-Type: text/html
Here is where the extra CRLF would be recognized ...
... and here is where the message body would begin

SuzyUK

WebmasterWorld Senior Member suzyuk us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3623733 posted 9:31 pm on Apr 10, 2008 (gmt 0)

Wondering how one can see if IE (per version if different) is in quirks mode without changing content

<p>Which Mode?</p>
<h2><script type="text/javascript">
mode = document.compatMode;
document.write(mode);
</script></h2>
<hr>
<ul><li>BackCompat = Quirks Mode</li>
<li>CSS1Compat = Standards Compliance Mode</li></ul>

Not certain where this is headed?

Me neither.. I just read somewhere today that whitespace won't trigger Quirks if indeed it is really whitespace - I don't understand that?

I can see that multiple returns don't trigger backCompat mode those are done in an editor that that presumes to know the encoding.. I can't help but think this could be a throwback to the days when windows text editors

I got to reading some before I ran out of time (and asked here) and landed down the road of BOM and character encoding and how the old "headers already sent message" in PHP explained that whitespace was not always as it appeared..

I just want to see if there's still any good reason to advise no whitespace before Doctype for IE CSS troubles.

yes SWA, anything at all (with the possible exception of 'true' whitespace?) before the Doctype causes Quirks in IE6 this is partially still true of IE7, except for it the <xml prolog> no longer triggers quirks and possibly, depending on the outcome here, neither does whitespace.. a good ol' comment does though as does a simple "<!>"

I think the thing I see mainly when troubleshooting is - if there's a huge amount of whitespace before a Doctype it's usually been generated by some server side code. ASP.Net is bad but I don't know why, does their "runat" code, sorry terminology is probably wrong, generate something?

Setek

5+ Year Member



 
Msg#: 3623733 posted 1:22 am on Apr 11, 2008 (gmt 0)

I thought it might be a difference between CRLF vs. CR only vs. LF only documents, but I didn't find anything.

So.. we advise "no characters before doctype declaration, but whitespace is fine"?

Even if so, a bunch of whitespace above a doctype declaration isn't particularly useful... might as well keep telling everyone to remove it :P

We'll keep it hush hush and one day it'll be a big Government conspiracy...

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3623733 posted 9:21 pm on Apr 16, 2008 (gmt 0)

Me neither.. I just read somewhere today that whitespace won't trigger Quirks if indeed it is really whitespace - I don't understand that?

I am assuming the person that wrote that was referring to whitespace as defined in the RFC, linear white space (LWS) which is carriage return, linefeed, space, and horizontal-tab.

CR       = <US-ASCII CR, carriage return (13)> 
LF = <US-ASCII LF, linefeed (10)>
SP = <US-ASCII SP, space (32)>
HT = <US-ASCII HT, horizontal-tab (9)>

I can have any of these whitespace characters ahead of my DOCTYPE and remain in standards mode with both MSIE6 and Mozilla. Perhaps they are referring to the other "whitespace" characters, such as control characters? I just inserted a <US-ASCII BS, backspace (8)> character before the DOCTYPE and it threw MSIE into quirks mode. Mozilla remained in standards mode. I tried the ESC character as well with the same results.

For the sake of this discussion, consider the response as being either the header fields or the message body, which are separated by the extra CRLF as mentioned earlier. I think if you are considering what throws quirks mode you may have to focus on the message body itself. It seems as though any LWS is fine in the message body and doesn't trigger quirks mode, at least not in today's browser. However, you start throwing in control characters and that is another story.

In regards to server-side technology, yes, I imagine either a failing interpreter or a poor developer could throw you into quirks mode unexpectedly. I have never seen the PHP interpreter do this on it's own, but I as the programmer can indeed invoke quirks mode by inserting those characters in the message body. Take the following example, append this to the front of your example, SuzyUK, and save the file with a .php extension so your server parses it as PHP:

<?php print str_repeat [php.net]("\r\n", 10); ?> 
<p>Which Mode?</p>
<h2>
<script type="text/javascript">
mode = document.compatMode;
document.write(mode);
</script>
</h2>
<hr>
<ul><li>BackCompat = Quirks Mode</li>
<li>CSS1Compat = Standards Compliance Mode</li></ul>

That single line of PHP will write out 10 CRLF and neither browser will go into quirks mode. However, replace that line of PHP with this line which prints out a single backspace character and MSIE6 will indeed go into quirks mode.
<?php print chr [php.net](27); ?>

To summarize, I think malformed header fields would cause issues well before quirks mode might be invoked. I don't have the time to test the theory right now but if somebody else could ...

Achernar

5+ Year Member



 
Msg#: 3623733 posted 10:32 pm on Apr 16, 2008 (gmt 0)

SuzyUK: a non-breakable space (ALT+0160 aka &nbsp;) will trigger quirks in IE6.

SuzyUK

WebmasterWorld Senior Member suzyuk us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3623733 posted 3:02 pm on Apr 18, 2008 (gmt 0)

Thanks coop, I'll need to re-read all that a few times, I did as you said and see what you mean.

a non-breakable space (ALT+0160 aka &nbsp;) will trigger quirks in IE6.

so it does! that'll not be true whitespace then ;)

so for us who've advised 'trim the whitespace' then that's probably still the best advice as we've no way of know via viewing the code what is causing it.. setek yea we'll keep hush hehe.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved