简体   繁体   中英

JavaScript files are not properly loaded on Amazon EC2 server

In the application file, I am loading JS like this:

 %script{:type => 'text/javascript', :src => 'https://www.google.com/jsapi'}
 %script{:type => "text/javascript", :src => "http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"}
 %script{:type => "text/javascript", :src => "/assets/jquery_ujs.js?body=1"}

I need to load them through the %script tags. But the JS doesn't work. When I open Firebug to find out why, there is following:

Uncaught ReferenceError: jQuery is not defined jquery_ujs.js?body=1:394

All the paths above are correct, when I display HTML output of generated app and click on the paths to JS files, all are working.

Thus, what's wrong? Why these errors?

See if jQuery is being loaded twice. In Chrome Dev Tools, load the network tab then reload the page. Click the Name column to sort by name and see if you have two jQuerys in there. This happened to me before. The second load of jQuery overwrites the jQuery namespace and whatever libraries were associated with that namespace don't work.

The problem was in the javascript files, that were loaded externally (from 3rd party providers, like Github or Google).

When I downloaded these files and saved them into the /assets folder, everything was working well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM