Vite: Move <!DOCTYPE html> to top of generated HTML

Created on 22 May 2020  路  3Comments  路  Source: vitejs/vite

Below is output document...

<script type="module">
import "/vite/hmr"
window.__DEV__ = true
window.__BASE__ = '/'
window.process = { env: { NODE_ENV: 'development' }}
</script>
<!DOCTYPE html>
<html lang="en">
<head>

should <!DOCTYPE html> be at the top?

Most helpful comment

This isn't true, it causes styling bugs because the DOCTYPE is ignored if it's not at the very top of the response.

Example from my own project, here is what it looks like in Vite:

image

Here is what it looks like in production:

image

The browser applies different user agent styles to different doctypes, so it's important that we can server the correct one.

All 3 comments

That's fine, this is only injected during dev and all supported browsers can handle that.

This isn't true, it causes styling bugs because the DOCTYPE is ignored if it's not at the very top of the response.

Example from my own project, here is what it looks like in Vite:

image

Here is what it looks like in production:

image

The browser applies different user agent styles to different doctypes, so it's important that we can server the correct one.

fixed in 0.20.2

Was this page helpful?
0 / 5 - 0 ratings

Related issues

albertog picture albertog  路  4Comments

Hoverhuang-er picture Hoverhuang-er  路  3Comments

TrungRueta picture TrungRueta  路  4Comments

maxxcs picture maxxcs  路  3Comments

stefnotch picture stefnotch  路  3Comments