What is the best strategy for providing the right new version of jQuery (1.4.2) in usercript that modifies a page that already has an older version of jQuery (1.3.1) installed?
Preferably, the original page continues to use the '$' sign, and my script uses the alias assigned jquery.noConflict().
According to the answer to this question, any additional version that you want to download should be placed above the original script tag. Here I am a little confused, since I am under the impression that GreaseMonkey is loading the script after loading the page?
EDIT: One thought is pointed out in usercript, add a script tag for jQuery 1.4.2, set an alias, and then add a script tag for 1.3.1 again so that you don’t break the source code of a page that uses 1.3.1 functions.
var code142 = function() {
gj = jQuery.noConflict(true);
alert("142...");
alert(gj);
alert(gj().jquery);
}
var script = document.createElement("script");
script.src = 'http://code.jquery.com/jquery-1.4.2.min.js'
document.documentElement.appendChild(script);
var script = document.createElement("script");
script.textContent = '(' + code142.toString() + ')();';
document.documentElement.appendChild(script);
But this will require loading the jQuery library 3 times per page. Is there a better way?
EDIT 2: It seems that the source page can still use its copy of 1.3.1, although the GM script provided a copy of 1.4.2, they can coexist for as long as I use the new alias ( gj) to refer to the 1.4 object. 2 jQuery inside code142().
If nothing happens, this will be my decision. I hope this is helpful to other people who may run into this problem.