2

I am working on a project where there's multiple libraries loading in the head. The CMS being used is WordPress.

Through the wp_head, there's an enqueued script for the latest version 1.7.1, but just below it there's a set of script files that begins with version 1.4.

Here's a simple visual flowchart:

<head>    
  <script jQuery 1.7.1>
  <script jQuery 1.4>
  <script Colorbox>
  [7 more scripts dependent on 1.4 here]
</head>
...
<footer>
  <scripts that can use either 1.7.1 or 1.4>
</footer>

My understanding is that since jQuery 1.4 is below 1.7.1, that it is effectively the library being used.

Is it possible to rearrange the scripts so that those dependent on 1.4 can only be used by 1.4 then the rest by 1.7.1? For example:

<head>    
  <script jQuery 1.4>
  <script Colorbox>
  [7 more scripts dependent on 1.4 here]
  <script jQuery 1.7.1>
</head>
...
<footer>
  <scripts that can use either 1.7.1 or 1.4>
</footer>

See how I moved 1.7.1 down? Will 1.7.1's placement in the head below the 1.4 scripts affect the 1.4 scripts?

Is there a way to detect which version of jQuery is being used throughout the page?

4
  • 1
    Is the real problem a piece of code that isn't running on 1.7.1? You should opt to try to run one version (and probably the latest one). And, yes, the last version of jQuery included will be the one used. Commented Feb 4, 2012 at 2:27
  • It's not a piece of code. There's literally 6 or 7 files that were written when 1.4 was just out and they never updated it. I've tried using those scripts with version 1.7.1 but they break. It's not my responsibility to recode that script and they don't want to take the time to update the script right now for budgetary reasons. So, I'm forced to run 2 libraries until they resolve the problem. When I came into the project initially, there were literally 4 libraries loading throughout the site! Madness! Commented Feb 4, 2012 at 2:36
  • The longer you wait to make an upgrade like this, the more painful it will be. You'll save time (and $$) in the long run if you do the tough thing now. Commented Feb 4, 2012 at 2:38
  • I don't disagree! :) It's not my fight to win. It's completely up to the client. This is why I wanted to find the answer to my original questions! Commented Feb 4, 2012 at 2:42

2 Answers 2

2

please define those in "those dependent on 1.4", It is never a good idea to work back versions just for one part of a website. If it is multiple websites running the same header you might want to try and load in a php (databased) field and set the library that needs to be used in there. My advice would be that if indeed a part of your code doesn't work with the new library, update that code. And always use the latest JQuery :)

Sign up to request clarification or add additional context in comments.

7 Comments

I agree with you, Sam. Sadly, it's the client's decision whether to upgrade those 1.4 dependent scripts. To be brief, the functionality of several of the scripts break with newer jQuery versions so I'm forced to keep jQuery 1.4 library intact for just for these specific scripts. If I had it my way, they'd be updated. But, I'm getting paid only to do what they tell me!
So the question really is, with jQuery 1.7.1 below jQuery 1.4 and its dependent scripts, those 1.4 dependent scripts will instead be using 1.7.1, right?
yes, Javascript compiles from top to bottom :) so the $ that JQ uses gets overwritten by the new library included.
Btw, I ment to add my story as a comment, somehow ended up as answer, my bad :)
So to beat a dead horse, if v1.7.2 is loaded in the footer, then it will overwrite 1.7.1 and 1.4? :) Will the jQuery dependent scripts all have to load 3 times with all three libraries in this example?
|
0

This should work as jQuery.noConflict(true) allows you to assign jQuery to any global variable and remove the original jQuery variable from the global namespace.

<head>    
  <script jQuery 1.4>
  <script type="text/javascript">
     var jq14 = jQuery.noConflict(true);
  </script>
  [7 more scripts dependent on 1.4 here] // do a find and replace in all these, replacing $ and jQuery by jq14
  <script jQuery 1.7.1>
</head>
...
<footer>
  <scripts that can use either 1.7.1 or 1.4>
</footer>

It's hardly best practice to load two jQuery's on the same page, but if your client won't pay to upgrade the above shoudl hopefully provide at least a workable compromise.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.