I'm using a 3rd-party plugin, but I need to load the non-minified version of a specific JS file of the plugin, to avoid some image preloading caching; in the AJAX call when preloading some images, the minified JS uses param cache:!0
that breaks a specific functionality that I need...
So, the relevant code in the plugin reads:
wp_enqueue_script( 'woo-variation-gallery', esc_url( $this->assets_uri( "/js/frontend{$suffix}.js" ) ), array(
'jquery',
'wp-util',
'woo-variation-gallery-slider',
'imagesloaded',
'wc-add-to-cart-variation'
), $this->version(), true );
where $suffix
is calculated a little above (that's pretty standard in every plugin basically) like this:
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
So, temporarily I got around this by setting SCRIPT_DEBUG
to true
in my wp-config.php, but it doesn't feel right loading non-minified scripts site-wide just for a single script that needs to be loaded in its non-minified version...
So, is there any hook involved while enqueuing scripts, to hook into in my functions.php file in order to replace the script's $src
from the plugin's /js/frontend.min.js
to /js/frontend.min.js
before loading it?
I'm using a 3rd-party plugin, but I need to load the non-minified version of a specific JS file of the plugin, to avoid some image preloading caching; in the AJAX call when preloading some images, the minified JS uses param cache:!0
that breaks a specific functionality that I need...
So, the relevant code in the plugin reads:
wp_enqueue_script( 'woo-variation-gallery', esc_url( $this->assets_uri( "/js/frontend{$suffix}.js" ) ), array(
'jquery',
'wp-util',
'woo-variation-gallery-slider',
'imagesloaded',
'wc-add-to-cart-variation'
), $this->version(), true );
where $suffix
is calculated a little above (that's pretty standard in every plugin basically) like this:
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
So, temporarily I got around this by setting SCRIPT_DEBUG
to true
in my wp-config.php, but it doesn't feel right loading non-minified scripts site-wide just for a single script that needs to be loaded in its non-minified version...
So, is there any hook involved while enqueuing scripts, to hook into in my functions.php file in order to replace the script's $src
from the plugin's /js/frontend.min.js
to /js/frontend.min.js
before loading it?
1 Answer
Reset to default 0I was able to deal with this by letting the minified JS load normally, and then de-registering and de-queuing it, and finally enqueuing the non-minified one... Although personally I'd consider this an indirect method, it's probably the only way to do it, since there is obviously no way to hook into the process of originally enqueuing a script...
So my solution was inspired by a comment to my question by @TomJNowell and by this answer to another question also!
So the code I used was this:
add_action('wp_enqueue_scripts', 'wvg_load_non_minified_js', 10, 0);
function wvg_load_non_minified_js()
{
wp_deregister_script('woo-variation-gallery');
wp_dequeue_script('woo-variation-gallery');
wp_enqueue_script('woo-variation-gallery', esc_url(plugins_url() . '/woo-variation-gallery/assets/js/frontend.js'), array(
'jquery',
'wp-util',
'woo-variation-gallery-slider',
'imagesloaded',
'wc-add-to-cart-variation',
), WOO_VG_VERSION, true);
}
on('hide_variation.wvg', function() {
)... – Faye D. Commented Jan 9, 2022 at 3:34