[wp-trac] [WordPress Trac] #50328: Enqueue script and style assets only for blocks present on the page

WordPress Trac noreply at wordpress.org
Tue Oct 14 00:10:46 UTC 2025


#50328: Enqueue script and style assets only for blocks present on the page
-------------------------------------------------+-------------------------
 Reporter:  aduth                                |       Owner:  gziolo
     Type:  enhancement                          |      Status:  closed
 Priority:  normal                               |   Milestone:  5.8
Component:  Editor                               |     Version:
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests has-dev-    |     Focuses:  javascript
  note                                           |
-------------------------------------------------+-------------------------

Comment (by westonruter):

 In [changeset:"60930" 60930]:
 {{{
 #!CommitTicketReference repository="" revision="60930"
 Editor: Avoid enqueueing assets for blocks which do not render content.

 This change prevents scripts, styles, and script modules from being
 enqueued for blocks that do not render any HTML content. This is common
 for hidden blocks or blocks like the Featured Image block when no image is
 present. This change reduces the amount of unused CSS and JavaScript on a
 page, improving performance.

 A new filter, `enqueue_empty_block_content_assets`, is introduced to allow
 developers to override this behavior and enqueue assets for empty blocks
 if needed.

 The implementation involves capturing the asset queues before and after a
 block is rendered. The newly enqueued assets are only merged if the
 block's rendered content is not empty. This is done recursively for nested
 blocks to ensure that assets for inner blocks are also not enqueued if a
 parent block is hidden.

 Developed in https://github.com/WordPress/wordpress-develop/pull/9213.

 Props westonruter, aristath, peterwilsoncc, gziolo, krupajnanda, dd32,
 jorbin.
 See #50328.
 Fixes #63676.
 }}}

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


More information about the wp-trac mailing list