Reputation: 101
I have various web pages that have varying versions of jQuery included on them ranging from 1.4.2 upwards (yes, I know, it's a mess). I want to use the jQuery validation plugin on these pages but it requires jQuery 1.6.4+.
I know I can check the version of jQuery loaded and then load in a newer version if necessary but I'm unsure on how to reference them individually so the pre-existing JavaScript/jQuery code that's on the site can still use $ (as I know this works quite happily and I don't want to break it) and then the new plugin can use something else?
Any help or suggestions on a better way to do this would be greatly appreciated. Thanks.
Upvotes: 0
Views: 340
Reputation: 1907
Upvotes: 1
Reputation: 1437
Bad idea to do what you are doing.
If you really insist on having different jquery versions, you can always write some sort of a script manager. Basically you specify in your page's "config" what jquery versions are required on this page and the manager will load the appropriate one.
Something like:
// each page content before everything else
Manager.reguire("plugin 1", "1.4.7");
Manager.require("plugin 2", "1.4.4");
// Main layout <head section>
Manager.LoadRequiredVersions();
And the manager would just request the files for you, but don't forget that you might have to do some clever no-conflict stuff with jQuery if you want more than one on a single page. https://stackoverflow.com/a/1566644/486780
If it's one version per page then a manager would be the easiest option.
Upvotes: 2