loadjs: Avoiding duplicate downloads
I have the issue that scripts are loaded multiple times. I would have expected that scripts that have been loaded or are in the middle of loading won’t be loaded each time.
loadjs(['libraryA.js', 'usingA.js'], {
success: function() { /* done loading */ },
async: false
});
loadjs(['libraryA.js', 'libraryB_usingA.js', 'usingA_B.js'], {
success: function() { /* done loading */ },
async: false
});
In the above example libraryA.js gets loaded twice. I’ve been trying to avoid this issue by using bundleIds and loadjs.ready but this gets complicated quite quickly.
Am I missing something here?
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 2
- Comments: 19 (9 by maintainers)
@groupedsi @naltatis Here’s a new lightweight dependency manager I created called JohnnyDepp that implements the
requiremethod you requested: https://github.com/muicss/johnnydeppLet me know what you think.
Great! I’m happy to hear you like it. LoadJS and JohnnyDepp share the same underlying file loading code but their API’s are different enough that I thought combining them into one library would be confusing.
JohnnyDepp is tested across all major browsers and should be production-ready so give it a try and let me know if it works for you.
I get the same error using firefox and IE10 on win10. Chrome, Edge, IE11 on win10 are working fine.
There seems to be different behaviour in different browsers. In my tests on a Mac I have the duplication issue in Firefox. Chrome and Safari work as expected. I’ve set up your example in a CodePen: https://codepen.io/naltatis/pen/YQgGmy
When you open it in debug mode you can see the networking: https://s.codepen.io/naltatis/debug/YQgGmy/ZoMBajpbweJk
For now, I’m using @amorey’ recommendation and put all dependencies in a long list, remove the dups and run dem in
async: false.