Correct version handling for precached assets#317
Correct version handling for precached assets#317westonruter merged 3 commits intoGoogleChromeLabs:developfrom
Conversation
Per https://developers.google.com/web/tools/workbox/modules/workbox-precaching#explanation_of_the_precache_list, when the URL includes a version, the revision should be set to `null`. While investigating cache misses for precached assets, a discrepancy was found between how the plugin handles asset versions and how WordPress uses them when enqueueing those items.
|
Good catch. In looking at if ( isset( $this->args[ $handle ] ) ) {
$ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ];
}I've never actually seen this code executed before. I'm not sure it's even used in core. Nevertheless, I can see that Jetpack is also accounting for this code in how it reconstructs script URLs. |
|
Amusingly, I added that to Infinite Scroll. I don't think I've ever seen it used, but if the handle is passed as |
westonruter
left a comment
There was a problem hiding this comment.
I'll merge this next week.
westonruter
left a comment
There was a problem hiding this comment.
@ethitter One thing I realized after merging…
| } | ||
|
|
||
| if ( isset( wp_styles()->args[ $handle ] ) ) { | ||
| $version = $version ? $version . '&' . wp_styles()->args[ $handle ] : wp_styles()->args[ $handle ]; |
There was a problem hiding this comment.
Ditto for above:
| $version = $version ? $version . '&' . wp_styles()->args[ $handle ] : wp_styles()->args[ $handle ]; | |
| $version = $version ? $version . '&' . wp_styles()->args[ $handle ] : wp_styles()->args[ $handle ]; |
| } | ||
|
|
||
| if ( isset( wp_scripts()->args[ $handle ] ) ) { | ||
| $version = $version ? $version . '&' . wp_scripts()->args[ $handle ] : wp_scripts()->args[ $handle ]; |
There was a problem hiding this comment.
I just realized that in the context of the service worker, the & here should be & since the resulting URL will not be output to HTML for the browser to decode & back to &:
| $version = $version ? $version . '&' . wp_scripts()->args[ $handle ] : wp_scripts()->args[ $handle ]; | |
| $version = $version ? $version . '&' . wp_scripts()->args[ $handle ] : wp_scripts()->args[ $handle ]; |
Investigating cache misses for precached assets revealed that the plugin wasn't building URLs in the same way that the
WP_ScriptsandWP_Stylesclasses do.The revision handling also contributed to cache misses. Per https://developers.google.com/web/tools/workbox/modules/workbox-precaching#explanation_of_the_precache_list, when the URL includes a version, the revision should be set to
null.