Skip to content

Commit

Permalink
[Boost] Fix atomic caching (#31692)
Browse files Browse the repository at this point in the history
* Add a cachebuster, and rtrim minified content

* changelog

* Don't send content-length at all; it breaks on atomic'

---------

Co-authored-by: Mark George <[email protected]>
  • Loading branch information
thingalon and Mark George authored Jul 5, 2023
1 parent 800c77c commit 5e2e6c6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion projects/plugins/boost/app/lib/minify/Concatenate_CSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function do_items( $handles = false, $group = false ) {
} else {
$path_str = implode( ',', $css );
}
$path_str = "$path_str?m=$mtime";
$path_str = "$path_str?m=$mtime&cb=" . jetpack_boost_minify_cache_buster();

if ( $this->allow_gzip_compression ) {
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/boost/app/lib/minify/Concatenate_JS.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function do_items( $handles = false, $group = false ) {
} else {
$path_str = implode( ',', $js_array['paths'] );
}
$path_str = "$path_str?m=$mtime";
$path_str = "$path_str?m=$mtime&cb=" . jetpack_boost_minify_cache_buster();

if ( $this->allow_gzip_compression ) {
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
Expand Down
8 changes: 8 additions & 0 deletions projects/plugins/boost/app/lib/minify/functions-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
use Automattic\Jetpack_Boost\Lib\Minify\Config;
use Automattic\Jetpack_Boost\Lib\Minify\Dependency_Path_Mapping;

/**
* Get an extra cache key for requests. We can manually bump this when we want
* to ensure a new version of Jetpack Boost never reuses old cached URLs.
*/
function jetpack_boost_minify_cache_buster() {
return 1;
}

/**
* Cleanup the given cache folder, removing all files older than $file_age seconds.
*
Expand Down
5 changes: 4 additions & 1 deletion projects/plugins/boost/app/lib/minify/functions-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,12 @@ function ( $match ) use ( $dirpath, &$pre_output ) {
}
}

// Don't let trailing whitespace ruin everyone's day. Seems to get stripped by batcache
// resulting in ns_error_net_partial_transfer errors.
$output = rtrim( $output );

$headers = array(
'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $last_modified ) . ' GMT',
'Content-Length: ' . ( strlen( $pre_output ) + strlen( $output ) ),
"Content-Type: $mime_type",
);

Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/boost/changelog/fix-atomic-caching
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Minify CSS/JS: Fixed an odd caching issue on Atomic hosts

0 comments on commit 5e2e6c6

Please sign in to comment.