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?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.