-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin Proposal: Stylesheet Optimizer #1834
Comments
Related:
I wish tree shaking was easily possible, I heard you have experience in that 😃 |
Yeah, so do I. The problem is that pages which have arbitrary JavaScript could modify the DOM at runtime to make use of a CSS selector that isn't used at serve time. The AMP plugin can do tree shaking effectively because the AMP components are declarative so it can (mostly) figure out which CSS selectors could apply at runtime. |
I've milestoned Core-43258 now to add output buffering for 6.8. Related:
|
Example plugin which loads separate core block assets in the |
Overview
stylesheet-optimizer
About the plugin
Purpose
When using a classic theme, the stylesheets for blocks are enqueued on every page even when they are not used. Similarly, the main block-library stylesheet is also enqueued rather than enqueueing individual stylesheets for each block that is actually used on the page. This is all wasteful.
Scope
Enable the
should_load_separate_core_block_assets
filter by default, even for classic themes. Move all styles printed inwp_footer
up to theHEAD
in the original dependency order as if the filter had not been applied. (See also Core-61965.)This wouldn't necessarily depend on Optimization Detective since there would be no need for URL Metrics. All that is needed is the output buffering filter that Optimization Detective utilizes, and possibly the use of the HTML
TagProcessor (cf. #1546) for removing the footer styles and putting them in theHEAD
. Without Optimization Detective, we just need an output buffering mechanism which could replicate same output buffering used in that plugin, or else push to get Core-43258 done for 6.8.Then again, a subsequent enhancement for this plugin could be to leverage URL Metrics to detect what the critical styles are, so a dependency on Optimization Detective may make sense.
Rationale
The idea for a plugin was raised in a support forum topic by guillermo77.
The text was updated successfully, but these errors were encountered: