Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have built a few browser extensions that live in GMail. Since they are larger extensions, they incorporate jQuery 1.6.x.

I am using jQuery as a content script which means it is injected into GMail then my scripts reference jQuery as they are loaded afterwards.

I have found that when other extensions are installed alongside of my extensions and they incorporate earlier versions of jQuery the earlier versions are loaded first and my 1.6.x is ignored. The functionality I have that depends on 1.6.x no longer works, and that's a dealbreaker.

I'm trying to come up with an elegant solution for this. My first instinct is to namespace my version of jQuery, but loading jQuery twice seams clunky. Possibly testing for jQuery and then doing a diff, but that seems tedious.

Any thoughts?

share|improve this question

You could possibly do what the HTML5Boilerplate does:

<script>window.jQuery || document.write('<script src="js/libs/jquery-1.5.1.min.js">\x3C/script>')</script>
share|improve this answer

My personal feeling is that you probably shouldn't be injecting a third-party library into the page anyway. Keep in mind, that -- since it's a Chrome extension -- you only need to support a single browser anyway.

So that means things like subscribing to events, Ajax, and all the other stuff that jQuery abstracts are all pretty easy because you don't need to worry about cross-browser compatibility.

You can even use document.querySelector to get much of the functionality of jQuery's selectors (not all, though).

As a bonus, it'll make your extension much more light-weight by not loading 100KB of javascript into every page...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.