If you want to enforce the visitor to load the new version of your stylesheets and scripts, then (as @majick suggested) changing the version via query string is the way to go. This is just how the caching works.
My suggestion would be to make sure you update the theme version on every major, or crucial CSS and JS update, and use the theme version in the wp_enqueue_script
version arg (which is how most themes do it).
In case it’s a development issue (sometimes the caching gets in the way), you could consider making use of the SCRIPT_DEBUG
constant, which you can set in your wp-config.php
file. This is actually used to get a non-minified version of a file for development purposes, but you could use it to add a version to your wp_enqueue_scripts
action like this:
$theme = wp_get_theme();
$theme_version = $theme->get( 'Version' );
$dev_version = filemtime( get_template_directory_uri() . '/path/to.js' );
$version = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? $dev_version : $theme_version;
wp_enqueue_scripts( 'your-script', get_template_directory_uri() . '/path/to.js', array(), $version );
This way you could set it for all enqueues, and you would only have to change the setting in your wp-config.php
file.
solved Want to enforce the visitor to load the new version of your stylesheets and scripts [closed]