- From: Tsuyoshi Horo <notifications@github.com>
- Date: Mon, 06 Sep 2021 18:40:26 -0700
- To: w3ctag/design-reviews <design-reviews@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3ctag/design-reviews/issues/674/913929693@github.com>
This API is proposing a nicer and synchronous way to feature detect.
For `module`, we can use the `nomodule` attribute to detect the `module` type support as [this example](https://html.spec.whatwg.org/multipage/scripting.html#script-nomodule-example) shows.
> https://html.spec.whatwg.org/multipage/scripting.html#script-nomodule-example
> ```html
> <script type="module" src="app.mjs"></script>
> <script nomodule defer src="classic-app-bundle.js"></script>
> ```
(Note: Safari 10 did support `module`, but didn't support `nomodule`. So we need some hack like [this solution](https://gist.github.com/samthor/64b114e4a4f539915a95b91ffd340acc) not to load `<script nomodule>`.)
For `importmap`, there is no synchronous way to detect the `importmap` type support. As described in [the issue comment](https://github.com/WICG/import-maps/issues/171#issuecomment-521299519), we need to fetch an useless HTTP request.
> https://github.com/WICG/import-maps/issues/171#issuecomment-521299519
> ```html
> <script type="importmap">
> {
> "imports": {
> "vue": "/vendor/vue.js"
> }
> }
> </script>
> // ...
> <script>
> import ("vue").catch(() => {
> // We'll get here if we're in a browser that doesn't support import maps,
> // because import "vue" will fail (with no evaluation performed). In that case
> // the <script type=module> was also a no-op (mostly).
>
> const s = document.createElement('script');
> s.src = "./bundle.js";
> document.body.append(s);
> });
> </script>
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3ctag/design-reviews/issues/674#issuecomment-913929693
Received on Tuesday, 7 September 2021 01:40:39 UTC