Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#12136 closed bug (invalid)

Double script inclusion warning

Reported by: [email protected] Owned by: [email protected]
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.

Change History (7)

comment:1 Changed 11 years ago by dmethvin

Owner: set to [email protected]
Status: newpending

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

comment:2 Changed 11 years ago by [email protected]

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.

comment:3 Changed 11 years ago by dmethvin

Resolution: invalid
Status: newclosed

Nope. See http://api.jquery.com/jQuery.noConflict/

See http://latimes.com for a real-life site that includes multiple jQuery versions.

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

comment:4 Changed 11 years ago by [email protected]

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.$");

comment:5 Changed 11 years ago by ajpiano

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!") ?

comment:6 Changed 11 years ago by dmethvin

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.

comment:7 in reply to:  5 Changed 11 years ago by anonymous

Replying to 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.

Note: See TracTickets for help on using tickets.