[wp-trac] [WordPress Trac] #54018: Allow scripts registered via block.json to be enqueued in the footer
WordPress Trac
noreply at wordpress.org
Wed Oct 15 10:27:14 UTC 2025
#54018: Allow scripts registered via block.json to be enqueued in the footer
-------------------------------------+--------------------------
Reporter: jeremyfelt | Owner: (none)
Type: enhancement | Status: reopened
Priority: normal | Milestone: 6.9
Component: Script Loader | Version:
Severity: normal | Resolution:
Keywords: needs-refresh has-patch | Focuses: performance
-------------------------------------+--------------------------
Comment (by b1ink0):
@gziolo I have created a POC for handling this format:
{{{#!json
"viewScript": [
"file:./view.js",
{
"handle": "test-block-script",
"file": "file:./test.js",
"dependencies": [ "jquery" ],
"inFooter": true,
"strategy": "async",
"fetchpriority": "high",
"version": "0.1.0"
}
],
"viewScriptModule": [
"file:./module.js",
{
"handle": "test-block-module",
"file": "file:./test-module.js",
"dependencies": [ "@wordpress/interactivity" ],
"version": "0.1.0",
"fetchpriority": "high"
}
]
}}}
Below are the current minimal POCs:
https://github.com/b1ink0/wordpress-
develop/commit/3a7f33d3ee944c3b43fca82c75efc9572b894db7
https://github.com/b1ink0/gutenberg/commit/be3406208eec0d5a1b3684505752ad828e89669b
To make this work, I had to patch the `@wordpress/scripts` package to
support the new format. Since the build scripts don't expect an object
inside the `viewScript` array, the build was failing. For local testing, I
patched the `@wordpress/scripts` package directly inside `node_modules`.
This `block.json` format is based on this comment:
https://github.com/WordPress/gutenberg/issues/46954#issuecomment-1875279537
For this https://core.trac.wordpress.org/ticket/54018#comment:23 :
I'm not sure about the implementation when a `handle` is provided without
a `file`. I tried directly modifying `$wp_scripts` as a potential
solution, but since block registration is done in the `init` hook and
`wp_enqueue_scripts` is fired later, `$wp_scripts` does not contain the
enqueued scripts at that point.
The current behavior when only a handle is given is to return it directly,
which will be enqueued at block render time.
https://github.com/WordPress/wordpress-
develop/blob/ce984ff16c1084b6ee78b38d10f6d379fff6ffd5/src/wp-includes
/class-wp-block.php#L604-L620
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54018#comment:27>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list