How to handle multiple .require() in a session #29

Open
peol opened this Issue Mar 18, 2012 · 7 comments

3 participants

@peol
Collaborator

Currently, we don't handle this at all, we always execute the script for every .require(), which means that if we do:

basket.require({ url: 'jquery.js' }).wait(function() {
  basket.require({ url: 'jquery.js' });
});

This will make us insert a new <script> for each, overwriting any plugins loaded in-between, internal jquery caches etc. Should we just let this be, or should we track this internally and not insert the script more than once?

@addyosmani
Owner

I think we should handle this internally, but I'm wondering if it would make sense to also make this behaviour configurable (i.e have a sane default but one that can be overridden).

@sindresorhus
Collaborator

Yes, I also think we should handle this, but it's probably smart to have a way to override/disable.

@peol
Collaborator

Great. Would be great if anyone would have time to fix this, I'm working on the TTL stuff as we speak and the tests doesn't pass because of this. :D

@addyosmani
Owner

Might not be able to take a look at it today but can definitely do it this week! As long as no one beats me to it :p

@sindresorhus
Collaborator

"definitely do it this week" - you said it :p

When would anyone want to load a script twice? Just trying to come up with a reason it should be configurable. And why would anyone try to load the same script twice in the first place?

@peol
Collaborator

I think the problem is the other way around. Currently, if the dev by mistake basket.require() the same script more than once, we'll write over the old one (in this example, let's say he pulled in jQuery and then added some plugins, and then basket.require() jQuery again), he'll lose all the plugins. I'm not sure that's something we want to handle, but it might be nice from both this perspective, and possibly even for debugging (getting access to a list of what files that has been loaded, which we use to see if a script has been loaded already).

@sindresorhus
Collaborator

I think we should prevent it by default. If someone wants (for whatever insane reason) to load a script twice they could just basket.remove() it first right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment