Same version of jquery and multiple inclusions?

时间:2015-07-08 15:46:09

标签: javascript jquery html

I have a HTML file, lets call x.html, and this includes other HTML files. x.html file includes jquery library version 1.4.1. The same version of jquery seems to be included from other HTML files also. In the html of the page, I only see one instance of jquery library 1.4.1 included though.

My question - Would this same version multiple inclusion cause same or similar issue like the inclusion of multiple versions of jquery like the '$' or 'jQuery'not working as expected? or any other problem?

1 个答案:

答案 0 :(得分:1)

Problems arise from a sequence like this:

  1. page fragment imports jquery
  2. ... and then imports a jquery add-on that adds new functionality to jquery
  3. another page fragment imports jquery

The second import of the library will erase the work done by the add-on.

edit — jQuery add-on packages will (among other things) do stuff like:

jQuery.fn.something = function() { ...

They add methods to the jQuery package, in other words, so that code can use the facilities of the add-on via

jQuery(whatever).something(...)

When you import the jQuery library after that's been done, then all those changes to jQuery.fn (and any other changes made by add-on packages) are overwritten by the new copy of the jQuery library.

This is not something to be worked around. Or, to put it another way, the workaround is to not include jQuery more than once.