Re: [csswg-drafts] [css-cascade] Relax the restriction for @import to precede all other rules (#6334)

> Yes, there's implementation reasons. @emilio can give a proper explanation, but basically the UA wants to kick off loading all the stylesheets before it gets done parsing everything.

The details here are that browsers want to speculatively load `@import` rules that appear on `<style>` elements (which are fairly common unfortunately). Since you don't want to run a full CSS parser straight from the HTML parsing stage, and we only want to deal with `@import`, all browsers have a crappy-ish parser to scan for those URLs ([Gecko](https://searchfox.org/mozilla-central/rev/e8904db16ac45bff0ffe65e7289f8d2f00c48c48/layout/style/ImportScanner.h#17), [WebKit](https://searchfox.org/mozilla-central/rev/e8904db16ac45bff0ffe65e7289f8d2f00c48c48/layout/style/ImportScanner.h#17), [Chromium](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/parser/css_preload_scanner.h;l=39;drc=b2be29fa62337e3b1a1064b0a5719f80b373da84)). Allowing at-import anywhere would mean that we would need to both teach those scanners better (to deal with everything that may appear before an import rule), and run them on the whole input in order to do the preloading, which is quite unfortunate.

-- 
GitHub Notification of comment by emilio
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6334#issuecomment-856885145 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 8 June 2021 15:48:41 UTC