-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support gating with Progressive Enhancement or Graceful Degredation #153
Comments
For the existence of import attributes at all, this proposal has been so far considered like any other syntax proposal: either the platforms you are targeting support it, or you just don't ship the unsupported syntax (since a/b detection for syntax is generally difficult to do). If you want to feature-detect support for it, you would need some sort of eval to "hide" the syntax error so that it does not prevent the whole script from evaluating. This is the same as for any other new syntax: try {
new Function("import('', {})");
import("./modern.js");
} catch {
import("./legacy.js");
} You can also use a polyfill to add support for import attributes to older browsers, such as https://github.com/guybedford/es-module-shims. I think it would be incredibly useful if <script src="./modern.js" supports="css-modules and optional-chaining"></script>
<script src="./modern.js" supports="not (css-modules and optional-chaining)"></script> but I don't think this should be specific to import attributes -- it should be a generic mechanism for new JS features. |
Yes, a |
The best venue would be https://github.com/whatwg/html/issues, which is where the I remember that there was already some (unofficial?) discussion about this in the past somewhere, but I cannot find it anywhere. However, now that CSS has |
#56 (comment) is a relevant prior comment, with strawperson fallback syntax like so: // Import config with type "wasm" if possible, otherwise with type "json".
import '//test.local/config' with { type: "wasm" },
'//test.local/config' with { type: "json" }
// Import an empty module if `0m` is valid syntax, otherwise import a BigDecimal polyfill.
import '/empty.mjs' with { condition: { "validSyntax": "0m" } },
'/polyfills/BigDecimal.mjs' For the OP here, maybe something like import styles from './styles.css' with { type: "css" },
'./styles.mjs'; |
With import attributes being a feature of module imports that hoist, has there been thought put into how to support them with Progressive Enhancement or Graceful Degredation? Maybe this is enough:
But it feels so awkward to rely on
try/catch
with dynamic imports, which may later have more dynamically imported content included, powering the feature gate.This is so much like the move to ES Modules at large where we got access to
nomodule
to unlock access to a build with modules and a separate one without. Anoattributes
sort of attribute could be a great place to start the conversation.I remember a lot of feature checking conversation in the wake of
nomodule
, so maybe there are better options in the intervening years?The text was updated successfully, but these errors were encountered: