How can I change my javascript after it has been enqueued? [closed]
IT Nursery
May 13, 2022
0
Writing my first plugin, trying to make it as simple as possible. I put simplistic functions in the javascript just so it would let me know it was there. Afterward I changed the methods in the javascript. WP doesn’t recognize that the javascript changed. It looks like this:
function monthNext()
{
alert("In the haunted javascript file");
}
function monthPrev()
{
alert("This also works");
}
Now if I change the message in the alert box, it still alerts by the first message. I’ve tried dequeueing the script, inactivating and reactivating the plugin. I’m missing something. Can somebody help?
1 Answer 1
Your JS is being cached. In development, just empty your cache. But for production code, it’s helpful to note that wp_enqueue_scripts() takes a version argument that lets you set a script version number which is then added to the URL as a query string for cache busting purposes. (side note, the wp_register_script function is actually built into the wp_enqueue_script function, so you only need the one.)
This will append “?ver=1.1” instead, causing the browser to see it as a different file, and it will request it from the server instead of using a cached copy. More information about wp_enqueue_scripts() can be found here.