Opt to register styles in standard way #785
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #286.
By registering styles for the block in the traditional way, we can be guaranteed that the style will be printed to the page. There are scenarios (see #286) in which a block can be rendered and yet not printed, and this can prevent the inlined styles from being served. Styles were originally inlined in this way in order to prevent serving them when they weren't needed. Nevertheless, block themes now by default only print styles for blocks which are actually rendered on the page. And yet, classic themes do still print all styles for all registered blocks in the
head
unconditionally. In order to retain that conditional style printing, you can add the following plugin code:For classic themes, this has the effect of printing block styles in the footer since only at this point does WordPress know which blocks have been rendered. The downside here is that there may be a flash of unstyled content and critical styles may not be loaded soon enough.