Bypass PHP for known remote WordPress assets#3744
Draft
adamziel wants to merge 2 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What it does
Short-circuits PHP for WordPress static assets that are known to live outside the minified in-memory WordPress build.
When a request path appears in
wordpress-remote-asset-paths, the service worker fetches it directly from the WordPress static assets directory instead of first converting the request into a PHP request.Rationale
Minified WordPress builds intentionally omit many CSS, JS, image, and font files. Today, those requests still go through PHP, return a PHP-side 404, and only then fall back to the remote static assets directory.
The service worker already knows which paths were removed from the minified build, so the PHP round-trip is avoidable.
Local benchmark against
origin/trunkat309c44e9e, usingnpm run dev, Chromium headless, WordPress 6.8,?storage=temp&wp=6.8, 5 fresh browser contexts per branch. Numbers are medians./wp-admin/Implementation
PlaygroundWorkerEndpointkeeps the known remote asset paths collected during boot and exposes them throughgetWordPressModuleDetails().The service worker checks GET and HEAD requests against that path list before calling into PHP:
remoteAssetPaths.staticAssetsDirectoryand fetch it directly.This preserves existing behavior for unlisted paths, dynamic routes, and user-modified files. Empty asset-list entries are ignored, and root requests are never treated as remote assets.
Testing instructions
Benchmark artifacts were saved locally under
.context/benchmarks/first-two-prs/.