For your situation, I think what you have is a good approach.. Though I'm not completely sure why it would sometimes fetch twice and other times not. When I include jQuery, both jQuery
and window.jQuery
are defined. However, you can try changing the code to something like this for consistency in your situation:
//use &&
if ( (typeof jQuery === 'undefined') && !window.jQuery ) {
document.write(unescape("%3Cscript type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js'%3E%3C/script%3E"));
} else {
if((typeof jQuery === 'undefined') && window.jQuery) {
jQuery = window.jQuery;
} else if((typeof jQuery !== 'undefined') && !window.jQuery) {
window.jQuery = jQuery;
}
}
Note I'm very rusty on how js variables and the window
object work, and I'm just going off the code logic you have.
Just a side note (and you may already be doing this), put this js in a js file and add it with your module's layout xml
<layout version="x.x.x">
<handle>
<reference name="head">
<action method="addJs"><script>pathto/yourmodulesJs/check_jQuery.js</script></action>
</reference>
</handle>
</layout>
noConflict
?jQuery.noConflict();
:)