[csswg-drafts] @import-once (#6130)

trusktr has just created a new issue for https://github.com/w3c/csswg-drafts:

== @import-once ==
https://github.com/w3c/csswg-drafts/issues/4470 does give us the ability to manage duplication caused by files `@imporr`ing the same shared files: it allows us to place the (duplicate) imports in a high-cascade layer so that duplicates will not override the overrides of files that import the shared code to override the shared values.

(If that's not clear, let me know and I'll make a live example.)

Although this will help, it won't actually prevent the duplication.

Adding something like `@import-once` would solve the duplication problem regardless of cascade layers, but would still be complimentary to cascade layers.

`@import-once` would do what the name implies:

- On first occurrence of `@import-once "/some.css"` it behaves exactly like `@import`.
- On every occurrence after that for the same URL, it is simply skipped (no-op).

Only one stylesheet with content from `some.css` will be loaded. The behavior is based on the fully-resolved URLs, otherwise differing relative paths pointing to the same file would still load, causing duplication.

So it's not *completely* a no-op after the first occurrence: it still needs to resolve the URL, and it determines whether to continue or not based on the fully-qualified URL.

It only does what `@import` normally does when the fully-qualified URL has not been imported before.

Sidenote, CSS ES Modules will behave like `@import-once`. They also talked about making `@import` behave like this `@import-once` idea for various good reasons.

- [CSS Modules v1 Explainer](https://github.com/WICG/webcomponents/blob/gh-pages/proposals/css-modules-v1-explainer.md)
- [CSS Modules discussion issue](https://github.com/WICG/webcomponents/issues/759)



Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6130 using your GitHub account


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

Received on Tuesday, 23 March 2021 18:45:32 UTC