1

When trying to load my page i get an error saying: ReferenceError: jQuery is not defined ReferenceError: $ is not defined

here is a snippet of my code (this is in the head):

<link rel='stylesheet' href='https://static.rbxcdn.com/css/reset___90041b2af2fb6b9b7864ee66001ba812_m.css/fetch' />

 <link rel='stylesheet' href='https://static.rbxcdn.com/css/MainCSS___60fd933d0f625c9774382f154e19cc17_m.css/fetch' />

 <link rel='stylesheet' href='https://static.rbxcdn.com/css/page___6ff112f8c962911ea086de0a4c407e0d_m.css/fetch' />
 <script type='text/javascript' src='//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js'></script>
 <script type='text/javascript'>window.jQuery || document.write("<script type='text/javascript' src='/js/jquery/jquery-1.11.1.js'><\/script>")</script>
 <script type='text/javascript' src='//ajax.aspnetcdn.com/ajax/jquery.migrate/jquery-migrate-1.2.1.min.js'></script>
 <script type='text/javascript'>window.jQuery || document.write("<script type='text/javascript' src='/js/jquery/jquery-migrate-1.2.1.js'><\/script>")</script>
 <script type='text/javascript' src='https://js.rbxcdn.com/1a541fc4ac2f263b93132fffb807b336.js.gzip'></script>
Bert B
  • 11
  • 1
  • @Taplar because that would download and execute over the other one... – epascarello Dec 07 '16 at 18:34
  • 2
    @Taplar That's boilerplate code for including code from a CDN. You *want* the copy from the CDN (because it's likely to be in the user's cache from another site), but use your own if not. – Heretic Monkey Dec 07 '16 at 18:36
  • (not OP) but that code is to say if the CDN is down, it would load the next, but OP has an issue where the `migrate` would not load since that check is wrong. – epascarello Dec 07 '16 at 18:36
  • I don't think using document.write here is correct. – John Sparwasser Dec 07 '16 at 18:39
  • 2
    Possible duplicate of [document.write loading scripts dynamically](http://stackoverflow.com/questions/21729657/document-write-loading-scripts-dynamically) – Abin Thomas Dec 07 '16 at 18:40
  • Is jQuery defined within `.ready()`? The error would be expected as jQuery takes time to load and `window.jQuery` may not be defined when that ` – guest271314 Dec 07 '16 at 18:40
  • The answer is in the link Abin Thomas included. – John Sparwasser Dec 07 '16 at 18:42
  • @guest271314 Um, how would you be able to use ready when jquery is not loaded?? – epascarello Dec 07 '16 at 18:45
  • @epascarello How do we know that jQuery was not loaded? – guest271314 Dec 07 '16 at 18:46
  • @guest271314 Well the error is "jQuery is not defined" so I would assume it is not loaded. – epascarello Dec 07 '16 at 18:47
  • You should also consider going through your script and updating any jQuery code so that you don't need the migrate script. – Heretic Monkey Dec 07 '16 at 18:47
  • @epascarello jQuery needs time to load. The script following request for jQuery is called without waiting for jQuery to load. Will try to find a post that made here which addresses this case. – guest271314 Dec 07 '16 at 18:48
  • 1
    @guest271314 That is not how synchronous loads of scripts work... – epascarello Dec 07 '16 at 18:48
  • @epascarello `window.jQuery` will not be immediately defined. That is error message. That does not mean that jQuery is not defined 1 to 3 seconds later. See http://stackoverflow.com/a/29808688/ – guest271314 Dec 07 '16 at 18:50
  • 1
    @guest271314 So you are saying it is not possible to do this? https://jsfiddle.net/moxsn6a0/ If that is the case that the way we code would be broken everywhere. – epascarello Dec 07 '16 at 18:57
  • @epascarello Ok. Got it, you are correct. See what you mean now about blocking where `async` is not set. Previously used pattern at link to load jQuery when not defined for https://github.com/guest271314/toggleStyles/blob/master/toggleStyles.js – guest271314 Dec 07 '16 at 18:57
  • @epascarello Given the circumstances, where is error generated from? Cannot reproduce http://plnkr.co/edit/IVycRDRt4xy8edORO5Vu?p=preview – guest271314 Dec 07 '16 at 19:05
  • @epascarello Was able to reproduce error by loading `document` at `file:` protocol, where `` produces `1a541fc4ac2f263b93132fffb807b336.js.gzip:13 Uncaught ReferenceError: jQuery is not defined`. The `src` at `document.write()` calls should also probably be full path to local resource – guest271314 Dec 07 '16 at 19:13
  • @BertB Are you loading the `html` `document` at `file:` protocol? – guest271314 Dec 07 '16 at 19:26

0 Answers0