Skip to content
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

Add an option to include the shim script as defer instead of async #195

Closed
JanPokorny opened this issue Aug 8, 2023 · 2 comments
Closed

Comments

@JanPokorny
Copy link

Although the es-modules-shims script recommends including it as async in their README, this can lead to bugs as on browsers that support executing type="module" scripts out of the box, the async script might not execute before the module, leading to the importShim function not being available: guybedford/es-module-shims#385

This can be mitigated by changing async to defer when including the shim -- deferred scripts go into the same queue as modules, thus it guarantees that the shim will be executed first, before the module.

@JanPokorny
Copy link
Author

JanPokorny commented Aug 14, 2023

As explained in the linked issue, it actually only makes sense to do this if the script needs to rely on importShim (which is only when there are no static imports to trigger the polyfilling mechanism). In the general case async is better than defer, but still having an option to choose between async/defer would be nice to allow for this edge case

@JanPokorny JanPokorny changed the title Include the shim script as defer instead of async Add an option to include the shim script as defer instead of async Aug 14, 2023
@dhh
Copy link
Member

dhh commented Jan 1, 2024

We're dropping the shim in version 2, so this is no longer relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants