Force update of a JS file in WP (prevent cache)

If this is the old register script:

wp_register_script( 'twstudio', get_theme_file_uri( 'build/js/script.min.js' ), array( 'jquery' ), filemtime( get_theme_file_path( 'build/js/script.min.js' ) ), true );

Then you should change it to:

wp_register_script( 'twstudio', get_theme_file_uri( 'build/js/script.min.js' ), array( 'jquery' ), '2.5.5', true );

Then the file gets a version number, witch means, it would be updated to all users. Then you are sure that there is no cache of the file.

Leave a Reply

Your email address will not be published. Required fields are marked *