[wp-trac] [WordPress Trac] #54018: Allow scripts registered via block.json to be enqueued in the footer

WordPress Trac noreply at wordpress.org
Tue Feb 15 08:33:15 UTC 2022


#54018: Allow scripts registered via block.json to be enqueued in the footer
---------------------------+------------------------------
 Reporter:  jeremyfelt     |       Owner:  (none)
     Type:  enhancement    |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Script Loader  |     Version:
 Severity:  normal         |  Resolution:
 Keywords:  has-patch      |     Focuses:  performance
---------------------------+------------------------------

Comment (by ocean90):

 I'd love to see this possible, although I think it should have been in the
 footer by default.

 Instead of having a single property I have thought about extending the
 properties to allow an array of objects. An example:

 {{{#!json
 {
 "editorScript": [
     {
       "path": "file:editor1.js",
       "footer": true,
       "data": {
             "async": true
       }
     },
     "file:editor2.js",
     "my-editor-script-handle"
   ],
   "editorStyle": [
     {
       "path": "file:editor1.css",
       "media": "print"
     },
     {
       "path": "file:editor2.css",
       "media": "(max-width: 640px)"
     },
     "file:editor3.css"
   ],
   "style": "file:style-blocks.css",
   "viewScript": [ "my-block-view-handle", "my-block-view-2-handle" ]
 }
 }}}


 * For back-compat it still allows passing only one handle or file
 * You can pass an array of handles and/or file
 * You can pass an array of objects with settings passed to
 `wp_register_style()`/`wp_register_script()`
 * `data` property can be used for `wp_script_add_data()`
 * Not in the example but passing a single object should probably be
 possible too

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54018#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list