[wp-trac] [WordPress Trac] #60647: Script Modules: Allow modules to depend on existing WordPress scripts
WordPress Trac
noreply at wordpress.org
Thu Mar 7 11:01:07 UTC 2024
#60647: Script Modules: Allow modules to depend on existing WordPress scripts
-----------------------------+------------------------------
Reporter: jonsurrell | Owner: jonsurrell
Type: feature request | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: Script Loader | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses: javascript
-----------------------------+------------------------------
Comment (by jonsurrell):
One concern with the proxy module approach was around the ordering of
script execution. For example, the proposed proxy module `@wordpress/a11y`
has an implicit dependency on the `wp-a11y` script. `wp-a11y` exposes
required global variables and therefore ''must be executed before''
`@wordpress/a11y`.
I've done some testing and research and it appears that the ordering of
scripts printed on the page will not be a problem. In summary, if the
scripts are not `async` or `defer` (by default they are not), and modules
are not `async` (by default they are not), they will executed in the order
we require.
-----
Enqueued scripts are printed as `script` tags without `async` or `defer`
attributes. [https://developer.mozilla.org/en-
US/docs/Web/HTML/Element/script#notes This means they "are fetched and
executed immediately before the browser continues to parse the page."]
**Enqueued scripts will be fetched and executed in the order they appear
on the page.**
Modules (`<script type="module">`) [https://developer.mozilla.org/en-
US/docs/Web/HTML/Element/script#defer are always treated as `defer`, which
means:]
> the script is meant to be executed after the document has been parsed.
If we put those together, we can see that scripts are executed before
parsing continues, while modules are executed after the document has been
parsed. This ordering means that modules can depend on scripts
independently of where the ordering of script tags on the page.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60647#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list