Skip to main content

Bug Tracker

Side navigation

#12136 closed bug (invalid)

Opened July 24, 2012 03:58PM UTC

Closed July 24, 2012 04:46PM UTC

Last modified July 24, 2012 05:33PM UTC

Double script inclusion warning

Reported by: Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:

When jQuery is included twice at the page, it just reinits. And that's pefectly fine. The modules that were used before become unavailable. But I think it's good idea at least notify users through debug.log that you are going to override already available instance. It might help someone figure out why the modules that are included into page aren't working.

Attachments (0)
Change History (7)

Changed July 24, 2012 03:59PM UTC by dmethvin comment:1

owner: →
status: newpending

What if someone wants to include two different versions of jQuery on a page?

Changed July 24, 2012 04:32PM UTC by comment:2

status: pendingnew

AFAIK, last will overwrite the previous. I'm just saying that it should notify somehow about this, instead of doing silently.

If you actually need two different versions, you'll have to modify the source slightly.

Changed July 24, 2012 04:46PM UTC by dmethvin comment:3

resolution: → invalid
status: newclosed

Nope. See

See for a real-life site that includes multiple jQuery versions.

If you don't want to include two versions, don't include them.

Changed July 24, 2012 05:10PM UTC by comment:4

I'm not raising the problem how to include two different version, but if it's untintentional. That happens when you include some 3rd party script, and this might take a while to realize what exactly happened. And why your scripts stopped working. Ofc user gonna open javascript console to see "$.moduleFunction is undefined" errors. Would it be nice to see "Overriding window.jQuery object" message on top?

That's just few lines of code just before window.jQuery = window.$ = jQuery;

if (debug && debug.log) {
  if (window.jQuery) {
    debug.log("Overriding window.jQuery");
  if (window.$) {
    debug.log("Overriding window.$");

Changed July 24, 2012 05:26PM UTC by ajpiano comment:5

I have heard this feature request before, and not only from someone who wanted a warning, but someone who actually wanted us to cache the entire jQuery.fn and then restore it to the new window.jQuery. Unfortunately, this is but one of many "common problems" one can encounter when using jQuery (it's one I vividly remember myself), and we can't afford to go adding and throwing warnings out from core to the console (or whatever happy console wrapper you're using at window.debug) to assist in debugging all of them. Otherwise, what's next... console.log("Sorry, that selection does not contain any elements!") ?

Changed July 24, 2012 05:30PM UTC by dmethvin comment:6

Indeed. If it's something you run into often while trying to debug unknown code, the best thing to do would be to create your own custom version that includes such checks. Or just look at the Network tab of your favorite browser to see that jQuery is being loaded multiple times. Every byte we add to the common code is downloaded literally millions of times a day across the Internet.

Changed July 24, 2012 05:33PM UTC by anonymous comment:7

Replying to [comment:5 ajpiano]:

console.log("Sorry, that selection does not contain any elements!")

That would be nice too. I'm just kidding. Yeagh, reasonable answer. Thank you both.