Skip to content

Instantly share code, notes, and snippets.

@SlexAxton
Created March 15, 2011 16:27
Show Gist options
  • Save SlexAxton/870973 to your computer and use it in GitHub Desktop.
Save SlexAxton/870973 to your computer and use it in GitHub Desktop.
How you might avoid loading jQuery twice (until it's a prefix)
// If you always need jQuery regardless
yepnope([
{
load: 'jquery.js'
},
{
test: Modernizr.something,
nope: 's1.js',
complete: function () {
$('*').s1();
}
},
{
test: Modernizr.somethingElse,
nope: 's2.js',
complete: function () {
$('*').s2();
}
]);
// If you can avoid loading jQuery altogether if both fail...
yepnope([
{
test: Modernizr.something && Modernizr.somethingElse,
nope: 'jquery.js'
},
{
test: Modernizr.something,
nope: 's1.js',
complete: function () {
$('*').s1();
}
},
{
test: Modernizr.somethingElse,
nope: 's2.js',
complete: function () {
$('*').s2();
}
]);
// But soon, we'll do a 'once' prefix, and you can do it like you tried before
// First include the prefix (concatenate it into the yepnope.js file)
yepnope([
{
test: Modernizr.something,
nope: ['once!jquery.js', 's1.js'],
complete: function () {
$('*').s1();
}
},
{
test: Modernizr.somethingElse,
nope: [ 'once!jquery.js', 's2.js'],
complete: function () {
$('*').s2();
}
]);
// Or if you live more dangerously, we could also have a 'once' filter (which would just look for the same url twice, and skip it if it happens again)
// First include the yepnope once filter (concatenate it into the yepnope.js file)
yepnope([
{
test: Modernizr.something,
nope: ['jquery.js', 's1.js'],
complete: function () {
$('*').s1();
}
},
{
test: Modernizr.somethingElse,
nope: [ 'jquery.js', 's2.js'],
complete: function () {
$('*').s2();
}
]);
@SlexAxton
Copy link
Author

I think my only aversion to adding in the duplication stuff is filesize. I was trying to keep only the most common cases supported by default, and then wanted to build a robust set of additions so the loader could work the way you want it. However, I could probably do this one thing with relatively little amount of code. I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment