0

I need my module just do load jQuery if it has not loaded before, I did the javascript, but it runs very fast and even using 'setInterval' etc. .. and in some cases they still going without waiting for jquery load my question would be, how can I load jQuery to my module only if it was not loaded before?

1 Answer 1

2

You can check for the global window.jQuery variable. If that is undefined jQuery is not loaded yet. Add the following to your modules layout XML or the local.xml

<default>
 <reference name="head">
 <block type="core/text" name="jquery_load">
 <action method="setText"><text><![CDATA[if (!!!window.jQuery){
 document.write('<script type="text/javascript" src="url/to/jquery/file.js"></script>');
}]]></text></action>
 </block>
 </reference>
</default>

This will be included in the head after all other javascript is loaded and you can be sure jQuery wasn't included. After that you can use jQuery

answered Apr 9, 2014 at 14:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.