Share CSS assets between templates preview to limit requests#73906
Share CSS assets between templates preview to limit requests#73906
Conversation
|
Size Change: +545 B (+0.02%) Total Size: 2.6 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in d07ea72. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/20572672471
|
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
What?
Optimizes CSS asset loading in iframe-based editor canvas to eliminate duplicate network requests across multiple template preview iframes.
Part of woocommerce/woocommerce#60795
Why?
The editor's iframe-based template previews were loading all block assets (CSS files) separately for each iframe, resulting in:
ERR_INSUFFICIENT_RESOURCESerrors frequently appearing in consoleExample of

ERR_INSUFFICIENT_RESOURCESin console:Example: A page with 10 template preview iframes would make 10 network requests for the same CSS file (even if cached, still consuming browser resources and TCP connections).
Note: While browser memory cache is enabled and returns 304/cached responses, each request still:
ERR_INSUFFICIENT_RESOURCESwhen scaled to hundreds/thousands of requestsThis optimization eliminates these requests entirely at the application level, starting the cleanup process to prevent resource exhaustion.
How?
1. Centralized CSS Fetching with Shared Cache
fetchCssFile()with URL-level caching (cssUrlCache) to ensure each unique CSS file is fetched only once2. Inline CSS Injection
<link>tags to inline<style>tags in iframesTesting Instructions
Testing Instructions for Keyboard
Specific examples - requests decrease
Example for templates including WooCommerce. Obviously the numbers would differ depending on your setup but the important thing is there's significant decrease in number of requests.
Scenario:
Gutenberg only:
The difference is extremely more significant when using plugins with multiple blocks anbd custom templates, e.g. WooCommerce
Performance optimisation
I did performance testing with Chrome's Lighthouse tool. Given the cache enabled there's nearly no difference but I still think this step is worth doing before (or along) with other optimisations, like images caching, etc. to further optimise the Editor previews.