Opened 14 months ago
Last modified 5 days ago
#56313 new enhancement
wp_enqueue_script needs to be able to handle modules (ES6/ES2020)
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Script Loader | Keywords: | needs-patch |
Focuses: | javascript, performance | Cc: |
Description
wp_enqueue_script should be augmented to add scripts with type="module" to pages.
Or a new function like wp_enqueue_module etc. should be created.
Also having the ability to ad a nomodule scrip-tag should be considered, even though ES6 ans ES2020 module support is very wide spread.
Especially ES2020 dynamic modules are a feature that really should be available for theme developers, as it is the best (standard conform) way to handle dynamically loading JS at runtime.
Change History (6)
#1
@
14 months ago
- Focuses javascript added
- Keywords 2nd-opinion added
- Severity changed from major to normal
#2
@
7 months ago
I came here looking for this! I wanted to add an additional concern/wrinkle. In supporting modules (which as noted can be done with a simple filter). It seems adding support for the `importmap` script type would make this a great addition to the script loader.
This would allow modules to have configurable imports -- enabling sharing modules between front/back ends without having to transpile. I'm sure there are other benefits, but this was the one that sent me looking for that support.
#3
@
3 months ago
- Focuses performance added
- Keywords needs-patch added; 2nd-opinion removed
- Milestone changed from Awaiting Review to Future Release
I think we should consider implementing this. Browser support for this is already in a good place. Having an official way to register modules will allow us to dynamically keep unused javascript from being sent to clients.
Related:
- Gutenberg #36716
- #48654 (Trac)
Hi @idad5, welcome back to Trac!
I think it makes sense that this is in Core territory rather than a third-party plugin. This should be reasonably straightforward. - it can even just be done through filters:
For now, I'll add the
2nd-opinion
keyword to get some thoughts on the enhancement from other contributors.