Uncaught ReferenceError: $ is not defined
Uncaught ReferenceError: jQuery is not defined
Is there any way to resolve this?
Jump to content
|Topic||Stats||Last action by|
|Even Sony doesn’t know why PS4 is selling so well||
|Trying to setup my external HD to home network for all computers to access...confused tho...||
|WZOR Talks About Windows (Codename) 9, Is a DP Imminent?||
|Microsoft has a Chromecast like dongle in the works and it has passed through the FCC||
|Poll: Should Windows 9/Threshold be X64 only?||
Posted 26 August 2012 - 19:02
Posted 26 August 2012 - 19:54
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.0.min.js"><\/script>')</script>
Posted 26 August 2012 - 20:08
Posted 26 August 2012 - 20:23
Posted 26 August 2012 - 21:11
Posted 26 August 2012 - 21:53
Posted 26 August 2012 - 22:53
You are loading script asynchronously, but have no dependency system implemented. It's not guaranteed that the dependencies are loaded in the correct order, and you are even trying to use jQuery dependent code from the same file that has document.write in it, which inserts the script tags to the document itself -- it doesn't itself load anything synchronously. This is what is causing your errors. Plus, you should not use document.write -- it's deprecated and doesn't even work with whole async model. It itself causes errors.
If you want to do asynchronous or on-demand loading please use a well refined existing script loader (AMD) library. There are ton of gotchas. Otherwise, just put the scripts at the end of the HTML page, before closing </body tag or to the <head> if scripts need to be loaded before the document body. You are just going to break **** if you do what you are doing right now. And as Tom's suggested fallbacks go, don't bother. They require that the connection times out before they even kick in. No one is going sit there in front of blank page for minutes.
If you are looking for a script loader, I would suggest either script.js or require.js. Both are great and do what is necessary to work consistently across browsers, while loading/initializing any dependencies in the correct order. There is also a LABjs that is very stable, but it's abandoned.
Lastly, do not load styles asynchronously. That's never recommended. Put stylesheets to the head unless you want some serious flashing, white pages and content shifting. Plus, styles have dependencies too.
Posted 27 August 2012 - 01:56
I mean, would appending them to make sense to what you're really trying to say or are you saying load them all separate?
Posted 27 August 2012 - 03:14
Join all the files together. Put everything and anything to the same bootloader file. jQuery, those scripts, everything.