Skip to content

Instantly share code, notes, and snippets.

@joemaller
Last active September 29, 2023 02:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save joemaller/ed7946d87451b812fa9ff1e8fed11934 to your computer and use it in GitHub Desktop.
How WordPress includes minimized script snippets for blocks in use.

WordPress v6.3.1 inlines styles for used blocks via the wp_head hook. However there is an additional wrinkle. If the SCRIPT_DEBUG constant is set and truthy, then a minimized copy of the styles will be inlined. The minimized copy is pre-generated and included with WordPress.

Code for choosing to use the min variant is in wp-includes/blocks.php:

// Check whether styles should have a ".min" suffix or not.
$suffix = SCRIPT_DEBUG ? '' : '.min';
if ( $is_core_block ) {
    $style_path = ( 'editorStyle' === $field_name ) ? "editor{$suffix}.css" : "style{$suffix}.css";
}

Minimized styles can be found in the source listings of each block in wp-includes/blocks/, look for pairs of files with .css and .min.css extensions.

The scripts themselves are enqueued from the Block::render method of wp-includes/class-wp-block.php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment