- The version parameter is appended as a query string (
<script src="http://example.com/script.js?ver=1.0.0">
) - Appending a query string to a url will force a cache bust, telling the client to re-download the asset
- Using php's
filemtime()
, you can get a files last modified time as a unix timestamp and use that as the version number - The result is that it will only cache bust when the file is modified
Last active
May 19, 2016 14:47
-
-
Save jonnymaceachern/4ec400786099569a17755d291be332cb to your computer and use it in GitHub Desktop.
Automatically cache bust scripts and styles
This file contains 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 | |
// wp_register_script( $handle, $src, $dependencies, $version, $includeInFooter ) | |
wp_register_script( 'my-script', get_stylesheet_directory_uri() . '/js/scripts.min.js', array( 'jquery' ), filemtime( get_stylesheet_directory() . '/js/scripts.min.js' ), true ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment