[wp-trac] [WordPress Trac] #61965: Provide a way for classic themes to opt into only loading styles for 3rd party blocks that actually render on a page

WordPress Trac noreply at wordpress.org
Fri Aug 30 12:59:13 UTC 2024


#61965: Provide a way for classic themes to opt into only loading styles for 3rd
party blocks that actually render on a page
-------------------------+-----------------------------
 Reporter:  fabiankaegy  |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 This ticket is coming out of a [Discussion in the Make WordPress
 Slack](https://wordpress.slack.com/archives/C02QB2JS7/p1724866722880979).
 And it it tangentially related to #61958

 As it stands today, classic themes load all the stylesheets of any blocks
 regardless of whether they are used on the page or not. This is partially
 due to the fact that for a long time the core blocks all had their styles
 bundled into one `wp-block-library` stylesheet.

 In order to change this behavior for core blocks a new flag
 `wp_should_load_separate_core_block_assets` was introduced which is
 enabled by default for block based themes. When this flag is enabled, core
 will no longer load the `wp-block-library` stylesheet but rather load
 individual stylesheets for only the blocks that are rendered on the page.
 Using the `should_load_separate_core_block_assets` filter classic themes
 can also opt into this behavior which does in theory solve this problem.

 However I am proposing that we add an additional flag that would allow
 classic themes to opt into the conditional loading of stylesheets without
 opting into the `wp-block-library` change.

 The reasons why I think this is important is that the refactor existing
 sites have to go through to move their large CSS codebases over to no
 longer depend on the loading order / specificity implications of having
 the `wp-block-library` CSS is a major effort. So it is going to take time
 for those sites to move over to having block specific stylesheets.

 In the meantime it would already be an arguably even larger performance
 improvement for these sites to no longer load the separate stylesheets of
 blocks we already have when they are not needed on the current page.

 Third party blocks often have much larger CSS files associated with them.
 Because they might for example load an entire Maps library, or other
 really large features.

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


More information about the wp-trac mailing list