I have an Umbraco 5 MVC3 project where i discovered that there where white spaces here and there. When investigating i discovered that my HTML looked really bad when "viewing generated source" in firefox web developer tool. For example it removes my doctype declaration and moves my meta-tags and stuff out of the head. Simplified code:
<!doctype html> <html class="no-js" lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>@ViewBag.Title</title> <link rel="stylesheet" href="@Url.Content("~/Content/Styles/style.css")"/> </head> <body id="" class="default"> <div id="wrapper"> <header id="banner" class="body"> <a class="ir logo" href="/"><h1>Christian </h1></a> <ul class="share"> <li id="facebook"><a class="ir" href="http://www.facebook.com/sharer.php?u=@Request.Url.AbsoluteUri">Facebook</a></li> <li id="twitter"><a class="ir" href="http://twitter.com/share?text=Christian">Twitter</a></li> </ul> @Html.Partial("nav") </header> <section id="content" class="body"> @RenderBody() </section> </div> <script src="@Url.Content("~/Scripts/plugins.js")"></script> <script src="@Url.Content("~/Scripts/script.js")"></script> </body> </html>
And the output begins like this
<html class="no-js" lang="en"><head></head><body id="" class="default">
Alright, i solved it. Took me a while. After Marapet suggested not to use "generated source" i tried normal "view source" in a bunch of browsers and got different results in all of them. When i tried to validate my source i got some weird complaints:
Non-space characters found without seeing a doctype first. Expected
Element head is missing a required instance of child element title.
And my personal favourite
Cannot recover after last error. Any further errors will be ignored.
Looked like there was something up with the doctype. Opened up notepad and pasted in there to "wash" the code from metadata, the way i do sometimes when pasting stuff in to tinyMCE. The text got formatted weird even in notepad. The doctype declaration had a smaller font size then the rest of the html.
So i opened it in notepad++ too and there i got a bunch of questionmarks in front of the declaration. I removed them and copied it back in to Visual Studio, saved and now everything works.
I think the reason i got this problem was that i copied snippets directly from the HTML5 Boilerplate on github.
If you want to check on the HTML generated by your server, you should use
View source (CTRL + U).