Skip to content

Instantly share code, notes, and snippets.

@plasticmind
Created December 14, 2012 02:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save plasticmind/4282236 to your computer and use it in GitHub Desktop.
Save plasticmind/4282236 to your computer and use it in GitHub Desktop.
Hash Cache
function my_load_meta() {
$script = '/js/script.js';
wp_enqueue_script( 'my-tools', get_template_directory_uri().$script, null, my_version_hash($script) );
$stylesheet = '/style.css';
wp_enqueue_style( 'my-style', get_template_directory_uri().$stylesheet, null, my_version_hash($stylesheet) );
}
add_action('wp_enqueue_scripts', 'my_load_meta');
// Create a hash of the file and pass it back for caching purposes
function my_version_hash($file) {
if(!$file) return false;
$full_path = get_template_directory() . $file;
return hash_file('CRC32',$full_path);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment