Created
September 26, 2013 19:54
-
-
Save danielbachhuber/6719651 to your computer and use it in GitHub Desktop.
Automatically append mtime to script and style versions for cache-busting action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Automatically append mtime to script and style versions for cache-busting action **/ | |
add_action( 'wp_enqueue_scripts', function() { | |
global $wp_styles, $wp_scripts; | |
foreach( array( 'wp_styles', 'wp_scripts' ) as $resource ) { | |
foreach( $$resource->registered as $name => $registered_resource ) { | |
// Not hosted here | |
if ( false === stripos( $registered_resource->src, home_url() ) ) | |
continue; | |
$file = str_replace( 'wordpress/', '', str_replace( home_url( '/' ), ABSPATH, $registered_resource->src ) ); | |
$mtime = filectime( $file ); | |
$$resource->registered[$name]->ver = $$resource->registered[$name]->ver . '-' . $mtime; | |
} | |
} | |
}, 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment