New Gutenberg Features: Conditionally loading block assets
One issue that I always found problematic with Gutenberg blocks is that it loads all assets all the time regardless of whether we use them in our projects or not. As of WordPress 5.8, we can work around this to only load the blocks that are used. We define our block as normal. When creating a block we can define separate scripts and stiles for the front and back end using code like the one below: ```php 'rivendellweb-test-block-script', 'editor_style' => 'rivendellweb-test-block-editor-style', 'style' => 'rivendellweb-test-block-style', 'script' => 'rivendellweb-test-block-frontend' ) ); ``` If you then also specify a filter that will only load the blocks assets when the block is actually used: ```php Edit on Github