JS file called twice in Wordpress
Posted
by
Dxr Tw
on Stack Overflow
See other posts from Stack Overflow
or by Dxr Tw
Published on 2012-11-24T04:27:00Z
Indexed on
2012/11/24
5:04 UTC
Read the original article
Hit count: 169
I'm trying to reduce number of requests by reducing number of JS files on WP site. I successfully combined around 7 javascript files into one (site.js
). Now, I'm using a plugin which has its own JS file (pluginA.js
), I want to include (pluginA.js
) in that site.js. However, if I simply copy pluginA JS content to site.js and then change location to /files/site.js
, firebug's NET tab shows that site.js is requested/called twice. I presume this is due to wp_enqueue_script
.
How can I make it not call site.js second time but just look into already loaded site.js?
Maybe there's alternative to wp_enqueue_script
?
Plugin's php file:
add_action( 'wp_enqueue_scripts', 'testplugin_scripts');
function testplugin_scripts() {
/*global $testplugin_version; */
$default_selector = 'li:has(ul) > a';
$default_selector_leaf = 'li li li:not(:has(ul)) > a';
wp_enqueue_scripts('test-plugin', site_url('/files/site.js', __FILE__), array('jquery'), $testplugin_version);
$params = array(
'selector' => apply_filters('testplugin_selector', $default_selector),
'selector_leaf' => apply_filters('testplugin_selector_leaf', $default_selector_leaf)
);
wp_localize_script('test-plugin', 'testplugin_params', $params);
}
© Stack Overflow or respective owner