Skip to content

Commit

Permalink
fixed a timing problem in JS-Minify
Browse files Browse the repository at this point in the history
  • Loading branch information
dreadkopp committed Mar 12, 2021
1 parent bfaa821 commit 29722dd
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Handler/JSMinify.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ public static function minify($buffer, $root_dir, $cache_dir, $inline_js, $publi
return self::finalize($buffer, $inline_js, $public_cache_dir, $cachedAndOptimizedName, $js_version);

}




if (file_exists($path)) {
unlink($path);
}
// find js sources and collect
$dom = new DOMDocument();
@$dom->loadHTML($buffer);
Expand All @@ -71,14 +74,17 @@ public static function minify($buffer, $root_dir, $cache_dir, $inline_js, $publi

}

if (file_exists($path)) {
unlink($path);
}
$fp = fopen($path, 'x');
if (fwrite($fp, $combined_js)) {
fclose($fp);

try {
$fp = fopen($path, 'x');
if (fwrite($fp, $combined_js)) {
fclose($fp);
}
} catch (\Exception $e) {
//prevent timing issues where file already exists due to multiple users accessing the page
}


return self::finalize($buffer, $inline_js, $public_cache_dir, $cachedAndOptimizedName, $js_version);
}

Expand Down

0 comments on commit 29722dd

Please sign in to comment.