Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
626 views
in Technique[技术] by (71.8m points)

asp.net - Does my HTML5 doctype have to be on the VERY first line?

I've always wondered whether whitespace before a DOCTYPE matters, but I can't seem to find any definitive information on the web. People say not to do it, but I can't see what effect it's likely to have, or even if the spec says it must be like that. I can't figure out if it triggers compatibility mode in IE or anything annoying like that.

The reason is, in my (crappy asp.net) code, I would much prefer to write:

<%@ Page language="c#" Codepage="65001" AutoEventWireup="true" %>
<%@ OutputCache Location="None" VaryByParam="none" %>
<!doctype html>

than:

<%@ Page language="c#" Codepage="65001" AutoEventWireup="true" %><%@ OutputCache Location="None" VaryByParam="none" %><!doctype html>

Because the first is neater. But the result of the top one is a few blank lines in your rendered html.

Not a huge issue. I've just always wondered if it matters :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes! comments and spaces may come first.

Here's the relevant section from the official HTML Specification


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...