Have you ever pushed out an update that included modifications to scripts or styles and then later had to tell someone to clear their cache or do a hard refresh in order to see the updates? There is actually a very simple way to avoid this scenario and force the browser to display the updated scripts and styles, even when a caching plugin is in use.
When using wp_enqueue_script() and wp_enqueue_style(), there is a $ver parameter (version) that allows you to pass a file version. This version number is used to determine if a new version should be displayed or not. By default, if you do not include the version number, WordPress automatically gives your script or style the same version number as the current install of WordPress.
Let’s assume that we have loaded a page that has a script set to version 1.0. After loading this script gets cached, so the next time we load the page, we’re actually viewing the cached version. If on our next visit, however, WordPress sees that the script is now version 1.1, it will force the browser to reload the script fresh instead of from cache. This ensures that the new version is always used.
If you have a large plugin or theme, keeping track of script and style version numbers can be difficult, so what I like to do is simply pass the same version number as the plugin or theme. This works really well because anytime an update is released, I have confidence that the new scripts / styles will be used. If no changes were made to any scripts or styles, no harm is done, but if changes were made, they will be displayed.
It’s really great because this even works with caching plugins installed, such as W3 Total Cache or WP Super Cache.
I usually define a constant that holds my plugin version number, like so (example take from Easy Digital Downloads):
define( 'EDD_VERSION', '1.3.2' );
In my script loader, I then use it like so:
wp_enqueue_script( 'edd-ajax', EDD_PLUGIN_URL . 'includes/js/edd-ajax.js', array( 'jquery' ), EDD_VERSION ); wp_enqueue_script( 'edd-validation', EDD_PLUGIN_URL . 'includes/js/form-validation.js', array( 'jquery', 'jquery-validation' ), EDD_VERSION );
Anytime I push out an update, I simply update my EDD_VERSION constant with the new version number and all scripts / styles then use this as their new version.