-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Using filemtime to cache bust editor assets is not reliable #18227
Comments
Hey @retlehs Ben Thank you for creating this issue! |
Thank you for the report. In the WordPress core we skip the part that sets version, letting WordPress handle it with its current version: |
Using What about for development? It depends upon whether the goal is for asset specific versioning or global versioning for all assets.
Notes about
👉 Which versioning is best for development: asset specific versioning or global versioning for all assets? |
I'm having trouble reproducing the problem. Env:
Steps: Using GB plugin version 9.9.3:
Updated the plugin to version 10.1.1:
@retlehs can you share more information on how you were able to reproduce this problem? |
Test 2Using: In 9.9.3, I made the following change to the CSS: :root{--wp-admin-theme-color:#00ba3e; whereas in 10.1.1 the color: :root{--wp-admin-theme-color:#007cba; Objective: Though the version numbers change as noted above, does each plugin's file get served up or is it the cached one? Start with 9.9.3Steps:
Results: <link rel="stylesheet" id="wp-block-directory-css" href="http://wpcore.local/wp-content/plugins/gutenberg/build/block-directory/style.css?ver=1615418702" media="all">
Update to 10.1.1Steps:
Results: <link rel="stylesheet" id="wp-block-library-theme-css" href="http://wpcore.local/wp-content/plugins/gutenberg/build/block-library/theme.css?ver=1615418787" media="all">
FindingsWhen updating from one version of the plugin to another:
|
I checked how we handle assets registered from We use filemtime in WP core for styles registered from block.json: For JS, we let webpack do its thing or the developer has to add an asset file with the required details: Once we migrate to webpack 5, we definitely should look into outputting a similar asset file for CSS and stop using |
Opened PR #29775 which proposes replacing There are other benefits to switching the approach such as simplifying the code and a teeny teeny tiny microseconds execution time boost. I think it's a good strategy to move forward with the fix. And then as @gziolo notes above, once we migrate to webpack 5, then the stylesheet versioning can also be used to further simplify the package style registrations and make it the same as the scripts registration for consistency. |
closed by #29775 - thank you @hellofromtonya and everyone else who helped! |
Describe the bug
Gutenberg is using
filemtime
in several areas when enqueueing assets, such as the editor CSSWhen updating Gutenberg, you can run into a scenario where outdated assets are being served because
filemtime
is cachedTo reproduce
Steps to reproduce the behavior:
build/editor/style.css
, on thever
query variable seen via dev tools or the source:Expected behavior
The latest version of assets should always be served
In #440 it was suggested to introduce a
GUTENBERG_VERSION
constant to avoid this problemScreenshots
Notice how the new breadcrumb bar (which is an awesome new feature ❤️) isn't styled correctly because the cache wasn't busted after updating from 6.7 to 6.8
The text was updated successfully, but these errors were encountered: