If you’re using the WordPress functions wp_enqueue_script and wp_enqueue_style (hint: you should be), you can take advantage of the 4th parameter to add a version number. I would suggest, if you’re adding the files to the theme, to use the file last modified date to set the version number, so that you don’t have to ever change the version number manually. If you’re managing a plugin, use the defined version number of your plugin with the enqueue functions.
* Load and set version for script and style files
// add site css. Parameter 4 uses file modified date to set version
wp_enqueue_style( 'site-css', get_stylesheet_directory_uri() . '/ css/site.css', array() , filemtime(get_stylesheet_directory() . '/ css/site.css'));
// NOTE: parameter 3, array(‘jquery’), means the script depends on the jquery file library
wp_enqueue_script('site-js', get_template_directory_uri() .'/js/site.js', array('jquery'), filemtime(get_template_directory().'/js/site.js'), true);
add_action( 'wp_enqueue_scripts', 'ifm_theme_scripts' )
You can view another example in this comment on the WordPress wp_enqueue_script page.
Using Grunt or Similar Task Automation Tool
If you’re utilizing Grunt or a similar task automation tool to process and minify your JS/CSS, there’s room to optimize this a bit. The following Grunt task can be used to write a new version number to a single file every time your JS/CSS is updated:
* Generate a new asset.version file for cache busting,
* based off of Date.now()
'Generate a new assets.version file for cache busting',
var date = Date.now();
grunt.file.write( 'assets.version', date );
Using this technique, you can determine the version number to use when enqueuing your assets once and use that same value for all of the files you’re enqueuing instead of having to touch each file individually.