ASP.NET: Page HTML head rendering
<p>I've been trying to figure out the best way to custom render the <code>&lt;head&gt;</code> element of a page to get rid of the extra line breaks which is caused by <code>&lt;head runat="server"&gt;</code>, so its properly formatted.</p>

<p>So far the only thing i've found which works is the following:</p>

<pre><code>    protected override void Render(HtmlTextWriter writer)
    {
        StringWriter stringWriter = new StringWriter();
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
        base.Render(htmlTextWriter);
        htmlTextWriter.Close();
        string html = stringWriter.ToString();
        string newHTML = html.Replace("&lt;title&gt;\r\n\t", "&lt;title&gt;")
                             .Replace("\r\n&lt;/title&gt;", "&lt;/title&gt;")
                             .Replace("&lt;/head&gt;", "\n&lt;/head&gt;");

        writer.Write(newHTML);
    }
</code></pre>

<p>Now i have 2 questions:</p>

<ol>
<li>How does the above code affect the performance (so is this viable in a production environment)?</li>
<li>Is there a better way to do this, for example a method which i can override to just custom render the <code>&lt;head&gt;</code>?</li>
</ol>

<p>Oh yeah ASP.NET MVC is not an option.</p>

<p><strong>EDIT:</strong></p>

<p>Im asking this with regards to SEO and just little bit perfectionism.</p>
