2

I am making a jQuery widget that will distributed to third parties. It is pretty simple, it will make an ajax call and put some content on a div on their page.

Is there an easy way a can give them everything they need in one file without the possibility of namespace conflicts?

I know I could make one file that has minimized jQuery, jQuery UI, and my own code, but that might create conflicts if they have other versions of jQuery. (For example, I might base my code off jQuery 1.7, and they might be running jQuery 1.3 for some reason.) So are there any good solutions to my problem?

1

4 Answers 4

2

I know its been a long time since you posted this question, but just in case anyone get here from google as I did, this is the solution you are looking for:

http://www.angrycoding.com/2011/09/managing-dependencies-with-requirejs.html

Summing up, you can use require to load a different jquery version for your app only, so it doesn't conflict with legacy code.

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

Comments

1

You should not create a minified version that has external libraries in it. Instead, clearly state your dependencies in your README. If someone uses an insufficient version of jQuery, tough luck.

For a more general approach at managing dependencies, have a look at require.js

Comments

1

Maybe using

var $j = jQuery.noConflict();

// Use jQuery via $j(...)
$j(document).ready(function(){
    $j("div").hide();
});

From http://api.jquery.com/jQuery.noConflict/

Comments

1

You can use jquery.noconflict to de-reference the last included version of jquery.

Directly after you include your version of jquery do something similar to:

var yournamespace = jQuery.noConflict();

then instead of the $ jquery operator you use your namespace similar to:

yournamespace("div p").hide();

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.