title: UTF-8 HTML and CSS files with BOM (and how to remove the BOM with Python)
body: <p>First, some background: I'm developing a web application using Python. All of my (text) files are currently stored in UTF-8 with the BOM. This includes all my HTML templates and CSS files. These resources are stored as binary data (BOM and all) in my DB.</p>
  
  <p>When I retrieve the templates from the DB, I decode them using <code>template.decode('utf-8')</code>. When the HTML arrives in the browser, the BOM is present at the beginning of the HTTP response body. This generates a very interesting error in Chrome:</p>
  
  <p><code>Extra &lt;html&gt; encountered.  Migrating attributes back to the original &lt;html&gt; element and ignoring the tag.</code></p>
  
  <p>Chrome seems to generate an <code>&lt;html&gt;</code> tag automatically when it sees the BOM and mistakes it for content, making the real <code>&lt;html&gt;</code> tag an error.</p>
  
  <p>So, using Python, what is the best way to remove the BOM from my UTF-8 encoded templates (if it exists -- I can't guarantee this in the future)?</p>
  
  <p>For other text-based files like CSS, will major browsers correctly interpret (or ignore) the BOM? They are being sent as plain binary data without <code>.decode('utf-8')</code>.</p>
  
  <p>Note: I am using Python 2.5.</p>
  
  <p>Thanks!</p>