Skip to content Skip to sidebar Skip to footer

Loading JQuery If Not Loaded - Failed Approach

This is what I have in : Inside m

Solution 1:

You might want to try looking at this answer. It may not be waiting until jQuery is fully loaded.


Solution 2:

With your code, the script will be loaded asynchronously. You need to add to the script tag an onload event that will trigger the parts that are dependent on jQuery.

If you want the script to be loaded in a synchronous way, use document.write:

window.jQuery||document.write(unescape("%3Cscript src='"+jQueryURL+"' type='text/javascript'%3E%3C/script%3E"));

The document.write technique is very common, just keep in mind that you cannot use it after your document has loaded (or else it will overwrite the whole page).

If you want to use dynamic loading on a larger scale, look at existing loader or AMD libraries.


Post a Comment for "Loading JQuery If Not Loaded - Failed Approach"