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().
If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
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 |
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: