{ By: "Nirmal V",
Date: 17/01/2016
Location: Kochi Ruby Meetup, Kochi }
Addy Osmani, Creator of Basket.js
Staff Engineer at Google working with the Chrome team
Creator of TodoMVC, Yeoman, Material Design Lite, Web Starter Kit
A passionate Javascript developer and author of open-source books like 'Learning JavaScript Design Patterns' and 'Developing Backbone Applications', Also, Contributed to open-source projects like Modernizr and jQuery. He is currently working on 'Yeoman' - an opinionated workflow for building beautiful applications, And also working on 'Polymer' and 'Service worker' libraries to make building applications on the web easier.
basket.require(details)
details: Either an object or an array of objects with the following fields:
basket.require({ url: 'jquery.js' });
basket.require(
{ url: 'require.js' },
{ url: 'require.config.js', skipCache: true },
{ url: 'libs.js' }
);
basket.require(
{ url: 'jquery.js' },
{ url: 'underscore.js' },
{ url: 'backbone.js' }
);
basket
.require({ url: 'jquery.js' })
.then(function () {
basket.require({ url: 'jquery-ui.js' });
});
basket.require({ url: 'jquery-2.0.0.min.js', key: 'jquery' });
basket
.require({ url: 'missing.js' })
.then(function () {
// Success
}, function (error) {
// There was an error fetching the script
console.log(error);
});
basket.require({ url: 'jquery.min.js', expire: 2 })
basket.require({ url: 'jquery.min.js', execute: false });
// fetch and cache the file
basket.require({ url: 'jquery.min.js' });
// fetch and cache again
basket.require({ url: 'jquery.min.js', unique: 123 });
basket.get(key)
key The key to lookup in the localStorage cache.
get() will return an object if script is found or false if not. The object contains the same data as that passed to require() when it was first loaded, with some additional details added:
var req
var ttl;
basket.require({ url: 'jquery.min.js', key: 'jquery' });
req = basket.get('jquery');
// know the lifetime
ttl = req.expire - req.stamp;
basket.remove(key)
key The key to remove from the localStorage cache.
remove() will simply remove a previously cached script from localStorage
basket
.remove('jquery.js')
.remove('modernizr');
basket.clear(expired)
expired If expired is true then only items that have expired will be removed. Otherwise all items are removed.
clear() removes item from the cache.
basket.clear();
basket.clear(true);
basket.isValidItem(source, obj)
basket.isValidItem = function (source, obj) {
return myVerificationFunction(source, obj);
};
@nirmalkamath