[wp-trac] [WordPress Trac] #63676: Blocks without rendered output still enqueue scripts and styles

WordPress Trac noreply at wordpress.org
Wed Jul 9 00:25:57 UTC 2025


#63676: Blocks without rendered output still enqueue scripts and styles
------------------------------------------+-------------------------
 Reporter:  westonruter                   |      Owner:  westonruter
     Type:  defect (bug)                  |     Status:  assigned
 Priority:  normal                        |  Milestone:  6.9
Component:  Editor                        |    Version:  5.9
 Severity:  normal                        |   Keywords:
  Focuses:  javascript, css, performance  |
------------------------------------------+-------------------------
 This is a follow-up to #50328.

 Scripts and styles are being enqueued for blocks even when the block
 content is not being rendered. This can commonly happen, for example:

 1. The Featured Image block renders no output when there is no featured
 image assigned.
 2. The Comments block renders nothing when comments are disabled.
 3. The Site Logo and Tagline blocks do not render anything if no logo or
 tagline are defined.
 4. A block's rendering may be suppressed using a plugin like Block
 Visibility.

 In all these cases, the scripts and styles are enqueued for the blocks
 even when the blocks are not rendered on the page. This is wasteful to
 included unused JS and CSS and it negatively impacts performance.

 To fix this, I suggest that `WP_Block::render()`,
 `wp_enqueue_block_style()`, and `enqueue_block_styles_assets()` be updated
 to check whether the rendered block content contains any HTML tag, and if
 so to only then proceed with enqueueing the scripts and styles. In
 contrast, if the rendered block content is an empty string or an HTML
 comment, then nothing should be enqueued.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63676>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list