## javascript – Update js file on wordpress page after making changes

Question

I added custom js script (ads.js) to my wordpress site in functions.php file like this:

wp_enqueue_script('ads', get_template_directory_uri() . '/js/ads.js', array( 'ads-REKLAMY' ), \$timestamp = filemtime( plugin_dir_path( __FILE__ ) . '/js/ads.js' ), true);


in this script I’m importing array of objects from another js file ads-REKLAMY.js, but the problem is the file is not updating when i change its content. I know it should be linked properly to update like the code before for example, but I don’t think I need this type of js file printed in header of the page as a html script tag. So the question is how do I link these two files, so changes in ads-REKLAMY.js file always apply.

The solution i have for now is this import line in ads.js file:

import { ads, adsP } from "./ads-REKLAMY.js?ver=1.1";


And enqueue script line in functions.php:

wp_enqueue_script('ads-REKLAMY', get_template_directory_uri() . '/js/ads-REKLAMY.js', array(), '1.1', true);


This ofc works but i need more elegant solution not to have to change versions manually everytime i make changes in my file with exported array of objects. I suppose need to change the import line to always get the right version of the ads-REKLAMY.js file.

0
2 months 2022-12-07T08:51:05-05:00 0 Answers 0 views 0