Skip to content

Instantly share code, notes, and snippets.

@tabacco
Created April 25, 2013 18:30
Show Gist options
  • Save tabacco/5461969 to your computer and use it in GitHub Desktop.
Save tabacco/5461969 to your computer and use it in GitHub Desktop.
Makes W3 Total Cache include each minified file's modtime in the filename, so that changes to css/js cause a new URL to be generated, allowing origin-pull CDN setups to work properly without manual invalidation.
--- a/w3-total-cache/lib/W3/Minify.php
+++ b/w3-total-cache/lib/W3/Minify.php
@@ -956,9 +956,10 @@ class W3_Minify {
$replace = $this->_minify_path_replacements();
$replaced = false;
foreach ($optimized as $file) {
+ $mtime = filemtime(w3_get_document_root() . '/' . $file . '.' . $type);
foreach($replace as $key => $path) {
if (strpos($file, $path) === 0) {
- $input[] = str_replace($path, $key, $file);
+ $input[] = str_replace($path, $key, $file) . ':' . $mtime;
$replaced = true;
break;
}
@@ -966,7 +967,7 @@ class W3_Minify {
if ($replaced)
$replaced = false;
else
- $input[] = $file;
+ $input[] = $file . ':' . $mtime;
}
$minify_filename = array();
@@ -1037,6 +1038,7 @@ class W3_Minify {
$exploded = explode(',', $uncompressed);
$replacements = $this->_minify_path_replacements();
foreach($exploded as $file) {
+ list($file, $mtime) = explode(':', $file);
if (!w3_is_url($file)) {
$prefix = substr($file,0,1);
$after_pre = substr($file, 1, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment