-
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
Register Assets: cache bust without filemtime #29775
Register Assets: cache bust without filemtime #29775
Conversation
For production, uses GUTENBERG_VERSION. For dev, uses microtime().
For production, uses GUTENBERG_VERSION. For dev, uses microtime().
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @hellofromtonya! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good, tested and works fine.
The one caveat might be for Gutenberg developers who do not set the WP_DEBUG constant, we probably will want to confirm that is mentioned in the docs somewhere. This can be a separate PR.
What constant are Gutenberg devs more inclined to set, if any? The PR can check for either |
I'm not sure, my guess is none on the PHP side. The expectation is more setting in at build using something like:
Here is the dev setup document: |
That makes. It's a reasonable expectation when working in |
Usually I have |
Thanks @aristath. In looking at constants predefined when running wp-env, both are set to
Switching to use |
When I tested it locally I saw the following:
This is also why PHP unit tests fail: https://github.com/WordPress/gutenberg/pull/29775/checks?check_run_id=2095591189#step:9:46 Overall, I like the idea. Thank you for working on it. We just need to find a way to make it work in the case when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my previous comment.
@gziolo I was looking at that earlier today, but then got sidetracked. I'm thinking about altering the decision to include checking if |
Switches the check around to determine if in production mode: - GUTENBERG_VERSION is defined - SCRIPT_DEBUG is not defined || is not true. Else, defaults to time().
@gziolo Commit 352e06a flips the check around by determining if in production mode, else it defaults to use
Testing locally When the above conditions are met: <link rel="stylesheet" id="wp-edit-blocks-css" href="http://wpcore.local/wp-content/plugins/gutenberg/build/block-library/editor.css?ver=10.1" media="all"> When adding <link rel="stylesheet" id="wp-edit-blocks-css" href="http://wpcore.local/wp-content/plugins/gutenberg/build/block-library/editor.css?ver=10.1" media="all"> When commenting out <link rel="stylesheet" id="wp-edit-blocks-css" href="http://wpcore.local/wp-content/plugins/gutenberg/build/block-library/editor.css?ver=1615918791" media="all"> When restoring the constant and then changing <link rel="stylesheet" id="wp-edit-blocks-css" href="http://wpcore.local/wp-content/plugins/gutenberg/build/block-library/editor.css?ver=1615918820" media="all"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work polishing the logic 💯
Description
#18227 reports times when outdated assets are being served when updating the plugin.
filemtime
is suggested as the root cause. Though I was unable to reproduce, it is conceivable that thefilemtime
could cause this problem. Why?The asset version strategy in the registration uses
filemtime
to generate a unique version based on the asset file's modification time. The return offilemtime
is cached in the realpath cache with an expiration defined by therealpath_cache_ttl
option in php.ini.This PR replaces
filemtime
with 2 different strategies:GUTENBERG_VERSION
as the asset version.time()
as the asset version.Note:
time()
is not cached in the realpath cache.Benefits:
How has this been tested?
Validated new version of the stylesheet loads when updating the plugin.
Steps:
build/build-directory/style/css
, changed:root{--wp-admin-theme-color:#00ba3e;
...gutenberg/build/block-directory/style.css?ver=1615418702
Results:
The updated stylesheet was served to the browser.
..gutenberg/build/block-directory/style.css?ver=1615469843
Checklist: