markjaquith / feedback

Ask @markjaquith anything!
42 stars 4 forks source link

how to dequeue script which actually enqueue from dependencies ?? #36

Closed mukundthanki closed 9 years ago

mukundthanki commented 10 years ago

Hi Mark,

To make clear my query I would like to show my use case here

Here is snippet from WooCommerce plugin which loads several scripts like this way.

wp_enqueue_script( 'wc-checkout', $frontend_script_path . 'checkout' . $suffix . '.js', array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ), WC_VERSION, true );

I want to dequeue wc-address-i18n so, I try to hook my function at wp_print_scripts and try to deregister it, but it also dequeue wc-checkout, which I dont want to dequeue,

I think its because of dependencies. Can we just manipulate only dependencies array ? I think it would be great if we can change dependencies and it should not affect enqueue script.

Can you please suggest me how can I solve this issue ? If its default functionality or something else ?

I have not approached WooCommerce makers, If its default then I need to approach WooCommerce.

johnbillion commented 10 years ago

I'm not Mark, but here's my response to this.

You're trying to achieve something which, by design, the dependencies API won't let you do. The wc-checkout script depends on wc-address-i18n. If you dequeue wc-address-i18n then wc-checkout is likely to break. This is why wc-checkout has marked it as a dependency.

The dependencies API prevents this breakage by dequeueing any scripts which depend on a script which isn't available.

You should be thinking about why you want to dequeue wc-address-i18n. There is probably a better way of addressing whatever issue it is you're having with this script.

markjaquith commented 9 years ago

What you could do is this: enqueue the dependency separately (or wait for something else to enqueue it, or not). And then enqueue your dependent script late, but check to see if the dependency is enqueued. Leave it out, if not.

But I would question why you need to do this. If your script can work with or without the dependency, can't you just make the JS do the test for the dependency?