Opened 10 months ago
Closed 10 months ago
#60232 closed enhancement (duplicate)
Script Modules API: Add import map polyfill
Reported by: | luisherranz | Owned by: | |
---|---|---|---|
Milestone: | 6.5 | Priority: | normal |
Severity: | major | Version: | |
Component: | Script Loader | Keywords: | |
Focuses: | javascript | Cc: |
Description
Now that WordPress is going to support import maps through the new Modules API, we need to make sure that they work on the majority of browsers because even though all the major ones already support import maps, some old versions still require a polyfill.
The requirements for such polyfill are:
- As all the modern browsers already support import maps and the polyfill is only for compatibility with old browsers, the polyfill should only be downloaded when the browser doesn't support import maps. So instead of the entire polyfill, we should add an inline script that checks if the polyfill is needed, and only add it in that case.
- The polyfill should only provide functionality for the import maps and nothing else to be able to safely remove it in the future. So we need to make sure that the polyfill doesn't include other functionality than just the import map polyfilling.
- The polyfill script will need to be maintained until the percentage of users using old browsers without import map support drops significantly.
I've opened an issue on the es-module-shims repository to start working on that, and this work should be finished before the WordPress 6.5 release.
Change History (5)
#3
@
10 months ago
Totally true. Thanks, @gziolo. Therefore, we can safely include es-module-shims
as it is today as long as we load it conditionally, and we will be able to remove it safely in the future.
Note: See
TracTickets for help on using
tickets.
We have a solution to conditionally load the polyfill only in the browsers that don’t implement natively import maps. Therefore there is no risk of introducing backward compatibility issue by exposing the additional features that polyfill provides because the same features don’t exist today for 90% of browser clients used by users as of today. It seems that mirroring how Gutenberg loads the polyfill would conclude the task.