kubetail-org / loadjs

A tiny async loader / dependency manager for modern browsers (899 bytes)
MIT License
2.57k stars 149 forks source link

Jquery problems #80

Open oranze opened 5 years ago

oranze commented 5 years ago

When loading Jquery and like example Jquery Cookie plugin via loader scripts not working. $ is undefined ... I think something with name spaces

amorey commented 5 years ago

By default LoadJS loads files with async=true which will cause problems if the plugin the loads before jquery. To avoid this you can use async=false:

loadjs(['/path/to/jquery.js', '/path/to/plugin.js'], {async: false});
oranze commented 5 years ago

I'm already solv this problem, but $.cookie just wont work... interesting what with delay 100ms it starting...

amorey commented 5 years ago

Can you share some example code? It doesn't sound like the problem is with LoadJS but if it is I can help you debug it.

Have you tried wrapping your jQuery code in $.ready()?

oranze commented 5 years ago

I have custom js framework for SAP application. This is hybrid of MVC and M -VC. Part of js code in Views. Logic is next I load index.html which must load all css and JS libraries, after that in sync mode I load framework.js and global app.js (global functions and etc), and after all this loading I load custom app.js which overload some methods, functions, variables for this domain with it own settings, templates and etc. Next step start custom_app.js and it load via JQuery template plugin the Views. One of view check $.cookie('key')... and on that moment $.cookie is undefined... so this is some Jquery Cookie plugin bug. But also in that model I can't use your plugin to load JQuery... if I start some JQuery code in templates it show $ is undefined bug... So now I just load Jquery lib via <script src... all others files loading fine

amorey commented 5 years ago

Have you tried using async: false?

oranze commented 5 years ago

Yes... like I sad help delay timeout between run $.cookie in template. may be this is $.cookie plugin bug, but may be this is Gecko engine bug... I get same bug in any Gecko browser. IE not tested yet

amorey commented 5 years ago

Here's a fiddle that loads jQuery and jQuery-cookie using LoadJS without a delay: https://jsfiddle.net/muicss/bd4L9omr/

Let me know if you're able to figure out the problem.