WordPress not updating the js file

2020-03-19 03:42发布

问题:

I am changing a JavaScript file, but it is not showing up in the browser. I cleared browser cache, I purged the cache through wp-admin, I removed the deflate code from .htaccess, but still it doesn't show up.

themes/soundwave/js/prettyPhoto.js?ver=4.2.3

when I add any other number in the ver for example, in the url if I type:

themes/soundwave/js/prettyPhoto.js?ver=4.2.3.1

the change is shown.

回答1:

During development, you could avoid the hassle of clearing the browser cache by passing a dynamic variable as the file's version when you enqueue it. For instance, the current time.

wp_enqueue_script( 'prettyPhoto', 'prettyPhoto.js', array(), date("h:i:s") );



回答2:

I had that problem. So at front-end page press Ctrl+U look at the script. If didnt changed, go to functions.php and try to define correct version.(in this exapmle 2.0.0)

wp_enqueue_script( 'theme-global-script', get_stylesheet_directory_uri(). '/js.js?ver=2.0.0', array( 'jquery'), '2.0.0', true );}