natemoo-re / microsite

Do more with less JavaScript. Microsite is a smarter, performance-obsessed static site generator powered by Preact and Snowpack.

Home Page:https://npm.im/microsite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove defer from inline scripts

Siilwyn opened this issue Β· comments

πŸ‘‹ hi it's me again, sorry!

I found my website build with microsite contains some HTML5 validation errors, quickly discovered the same errors are present on the hello-world example site.

For the full errors, check out the online W3C validation results.

Hey thanks for opening an issue! I can definitely remove the defer attribute from script tags.

The XML processing instructions, while not technically valid HTML5, do have well-defined, spec-compliant behavior. These are what enable partial hydration to support top-level fragments. I wrote a detailed explanation in #72, but the gist of it is that we need a non-rendering node to mark the beginning and end of the hydration points. If we were to wrap hydration points in a div or use any element (even hidden ones) to mark these points, it would interrupt document flow and break assumptions like being able to style .my-component + .my-component. Comments would be a valid HTML5 approach to this, but many minifiers and even some CDNs strip them by default, making them unsafe to rely on for critical behavior.

Ah I see, thanks for the insightful reply! It does feel a bit hacky but I can see the benefits too. Shall I close this or rename it to removing the defer attributes?

Totally agree! I think the hacky solution is unfortunately the only workable one in this case.

Yep, feel free to rename! I already fixed that on the v1.1.0 branch, which is just waiting on a Snowpack patch release to launch.