Skip to content

Commit 87c8274

Browse files
authored
Merge pull request #268 from GoogleChromeLabs/fix/workbox-cache-busting
Include workbox version in library path to ensure cache busting
2 parents f5ecce4 + 1263be6 commit 87c8274

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
/phpcs.xml
55
/.phpcs.xml
66
*.zip
7-
/wp-includes/js/workbox/
7+
/wp-includes/js/workbox*

Gruntfile.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = function (grunt) {
3232
},
3333
install_workbox: {
3434
command:
35-
"if [ -e wp-includes/js/workbox* ]; then rm -r wp-includes/js/workbox*; fi; npx workbox copyLibraries wp-includes/js/ && mv wp-includes/js/workbox-v* wp-includes/js/workbox",
35+
"if [ -e wp-includes/js/workbox* ]; then rm -r wp-includes/js/workbox*; fi; npx workbox copyLibraries wp-includes/js/",
3636
},
3737
create_build_zip: {
3838
command:
@@ -97,7 +97,7 @@ module.exports = function (grunt) {
9797
file
9898
);
9999
});
100-
paths.push("wp-includes/js/workbox/*");
100+
paths.push("wp-includes/js/workbox*/**");
101101

102102
grunt.task.run("clean");
103103
grunt.task.run("readme");
@@ -124,6 +124,13 @@ module.exports = function (grunt) {
124124
"$1" + version
125125
);
126126
}
127+
128+
const workboxVersion = grunt.file.readJSON("package.json")
129+
.devDependencies["workbox-cli"];
130+
content = content.replace(
131+
/define\(.+?PWA_WORKBOX_VERSION.+/,
132+
`define( 'PWA_WORKBOX_VERSION', '${workboxVersion}' );`
133+
);
127134
}
128135
return content;
129136
},

pwa.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
define( 'PWA_VERSION', '0.4.0' );
2121
define( 'PWA_PLUGIN_FILE', __FILE__ );
2222
define( 'PWA_PLUGIN_DIR', dirname( __FILE__ ) );
23+
define( 'PWA_WORKBOX_VERSION', json_decode( file_get_contents( PWA_PLUGIN_DIR . '/package.json' ), true )['devDependencies']['workbox-cli'] ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Replaced with version literal build.
2324
define( 'PWA_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
2425

2526
/**
@@ -95,7 +96,7 @@ function _pwa_print_build_needed_notice() {
9596
</div>
9697
<?php
9798
}
98-
if ( ! file_exists( __DIR__ . '/wp-includes/js/workbox/' ) || ! file_exists( __DIR__ . '/wp-includes/js/workbox/workbox-sw.js' ) ) {
99+
if ( ! file_exists( __DIR__ . '/wp-includes/js/workbox-v' . PWA_WORKBOX_VERSION ) || ! file_exists( __DIR__ . '/wp-includes/js/workbox-v' . PWA_WORKBOX_VERSION . '/workbox-sw.js' ) ) {
99100
add_action( 'admin_notices', '_pwa_print_build_needed_notice' );
100101
return;
101102
}

wp-includes/components/class-wp-service-worker-configuration-component.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function get_priority() {
5252
*/
5353
public function get_script() {
5454
$current_scope = wp_service_workers()->get_current_scope();
55-
$workbox_dir = 'wp-includes/js/workbox/';
55+
$workbox_dir = sprintf( 'wp-includes/js/workbox-v%s/', PWA_WORKBOX_VERSION );
5656

5757
$script = '';
5858
if ( SCRIPT_DEBUG ) {

0 commit comments

Comments
 (0)