Socket
Socket
Sign inDemoInstall

basket.js

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.5.0

license

15

_includes/api.md

@@ -34,2 +34,3 @@ ## API

* **unique** A token stored with the cached item. If you request the same item again with a different token the script will be fetched and cached again.
* **skipCache** Prevent storing the script in cache. Useful when you want load scripts in order, but only cache some. By default is *false*.

@@ -58,4 +59,16 @@ `require()` returns a [promise](http://wiki.commonjs.org/wiki/Promises/A) that will be fulfilled when each of the requested items has been fetched, or rejected if any item fails.

Multiple scripts will be requested. The scripts are requested asynchronously and so may load and execute in any order.
Multiple scripts will be requested. The scripts are requested asynchronously but executed in the same order as specified.
**Multiple scripts without caching some of them**
```javascript
basket.require(
{ url: 'require.js' },
{ url: 'require.config.js', skipCache: true },
{ url: 'libs.js' }
);
```
Multiple scripts will be requested. `require.config.js` will not be cached in localStorage. Useful if order of scripts execution is important but storing certain script is not needed, e.g. it changes with each request.
**Ordering dependencies**

@@ -62,0 +75,0 @@

10

lib/basket.js

@@ -48,3 +48,3 @@ /*global document, XMLHttpRequest, localStorage, basket, RSVP*/

var promise = new RSVP.Promise( function( resolve, reject ){
var xhr = new XMLHttpRequest();

@@ -68,3 +68,2 @@ xhr.open( 'GET', url );

// spec for xhr.timeout. So we do it ourselves.
/*
setTimeout( function () {

@@ -74,3 +73,3 @@ if( xhr.readyState < 4 ) {

}
}, basket.timeout );*/
}, basket.timeout );

@@ -87,3 +86,5 @@ xhr.send();

addLocalStorage( obj.key , storeObj );
if (!obj.skipCache) {
addLocalStorage( obj.key , storeObj );
}

@@ -99,2 +100,3 @@ return storeObj;

obj.type = obj.type || data.type;
obj.skipCache = obj.skipCache || false;
obj.stamp = now;

@@ -101,0 +103,0 @@ obj.expire = now + ( ( obj.expire || defaultExpiration ) * 60 * 60 * 1000 );

{
"name": "basket.js",
"version": "0.4.0",
"version": "0.5.0",
"description": "A script-loader that handles caching scripts in localStorage where supported",

@@ -17,3 +17,2 @@ "keywords": [

"homepage": "http://addyosmani.github.com/basket.js",
"bugs": "https://github.com/addyosmani/basket.js/issues",
"license": "MIT",

@@ -60,6 +59,3 @@ "author": {

"main": "lib/basket",
"repository": {
"type": "git",
"url": "https://github.com/addyosmani/basket.js"
},
"repository": "addyosmani/basket.js",
"scripts": {

@@ -70,11 +66,11 @@ "dev": "grunt",

"devDependencies": {
"grunt": "~0.4.0",
"bower": ">=0.10.0",
"grunt-contrib-qunit": "~0.3.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-jshint": "~0.6.2",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-connect": "~0.6.0",
"grunt-contrib-watch": "~0.5.1"
"bower": "1.x",
"grunt": "^0.4.0",
"grunt-contrib-concat": "^0.4.0",
"grunt-contrib-connect": "^0.8.0",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-qunit": "^0.5.1",
"grunt-contrib-uglify": "^0.4.0",
"grunt-contrib-watch": "^0.6.1"
}
}

@@ -1,7 +0,22 @@

![basket.js logo](https://raw.github.com/addyosmani/basket.js/gh-pages/asset/logo.png)
[![basket.js logo](media/logo_src.png)](http://addyosmani.github.com/basket.js)
[Basket.js](http://addyosmani.github.com/basket.js) is a script and resource loader for caching and loading scripts using localStorage
> [Basket.js](http://addyosmani.github.com/basket.js) is a script and resource loader for caching and loading scripts using localStorage
[![Build Status](https://secure.travis-ci.org/addyosmani/basket.js.png?branch=gh-pages)](http://travis-ci.org/addyosmani/basket.js)
[![Build Status](https://travis-ci.org/addyosmani/basket.js.svg?branch=gh-pages)](https://travis-ci.org/addyosmani/basket.js)
## Resources
### Examples
* [Load RequireJS modules with Basket.js](https://github.com/andrewwakeling/requirejs-basketjs/blob/master/basket-loader.js)
* [Loading CSS with Basket.js](https://github.com/andrewwakeling/basket-css-example)
### Articles
* [Basket.js: A JavaScript Loader With LocalStorage-based script caching](http://badassjs.com/post/40850339601/basket-js-a-javascript-loader-with-localstorage-based)
* [basket.js caches scripts with HTML5 localStorage](http://ahmadassaf.com/blog/web-development/scripts-plugins/basket-js-caches-scripts-with-html5-localstorage/)
* [Basket.js for improved script caching](http://t3n.de/news/basketjs-performance-localstorage-515119/)
## Contribute

@@ -16,3 +31,3 @@

We are also attempting to get as much unit test coverage as possible. For this reason, please add unit tests for any new or changed functionality and remember to lint and test your code using [grunt](https://github.com/cowboy/grunt).
We are also attempting to get as much unit test coverage as possible. For this reason, please add unit tests for any new or changed functionality and remember to lint and test your code using [grunt](http://gruntjs.com).

@@ -23,38 +38,30 @@ *Also, please don't edit files in the "dist" subdirectory as they are generated via grunt. You'll find source code in the "lib" subdirectory!*

To build the project, you will first need to install the necessary dependencies (such as [RSVP](https://github.com/tildeio/rsvp.js)) using [npm](http://npmjs.org) and [Bower](http://bower.io). Run:
To build the project, you will first need to install the necessary dependencies (such as [RSVP](https://github.com/tildeio/rsvp.js)) using [npm](http://npmjs.org) and [Bower](http://bower.io).
Run:
```sh
$ npm install & bower install
```
npm install && bower install
```
in the project root to get everything you need. Next, to actually build the project you will need [Grunt](http://gruntjs.com).Run
in the project root to get everything you need. Next, to actually build the project you will need [Grunt](http://gruntjs.com).
Run:
```sh
$ grunt release
```
grunt release
```
to generate a new release, otherwise just running `grunt test` will run the unit tests.
### Community articles, extensions and examples
#### Examples
* [Load RequireJS modules with Basket.js](https://github.com/andrewwakeling/requirejs-basketjs/blob/master/basket-loader.js)
* [Loading CSS with Basket.js](https://github.com/andrewwakeling/basket-css-example)
#### Articles
* [Basket.js: A JavaScript Loader With LocalStorage-based script caching](http://badassjs.com/post/40850339601/basket-js-a-javascript-loader-with-localstorage-based)
* [basket.js caches scripts with HTML5 localStorage](http://ahmadassaf.com/blog/web-development/scripts-plugins/basket-js-caches-scripts-with-html5-localstorage/)
* [Basket.js for improved script caching](http://t3n.de/news/basketjs-performance-localstorage-515119/)
## Team
[ ![Addy Osmani avatar](http://www.gravatar.com/avatar/96270e4c3e5e9806cf7245475c00b275.png?s=60) Addy Osmani ](https://github.com/addyosmani) (lead)
[ ![Sindre Sorhus avatar](http://www.gravatar.com/avatar/d36a92237c75c5337c17b60d90686bf9.png?s=60) Sindre Sorhus ](https://github.com/sindresorhus)
[ ![Andrée Hansson avatar](http://www.gravatar.com/avatar/9a22324229aebc599d46dacab494ce77.png?s=60) Andrée Hansson ](https://github.com/peol)
[ ![Mat Scales avatar](http://www.gravatar.com/avatar/c2b874c38990ed90a0ed15ac33bda00f.png?s=60) Mat Scales ](https://github.com/wibblymat)
| ![Addy Osmani avatar](http://www.gravatar.com/avatar/96270e4c3e5e9806cf7245475c00b275.png?s=60) | ![Sindre Sorhus avatar](http://www.gravatar.com/avatar/d36a92237c75c5337c17b60d90686bf9.png?s=60) | ![Andrée Hansson avatar](http://www.gravatar.com/avatar/9a22324229aebc599d46dacab494ce77.png?s=60) | ![Mat Scales avatar](http://www.gravatar.com/avatar/c2b874c38990ed90a0ed15ac33bda00f.png?s=60) |
|---|---|---|---|
| [Addy Osmani](https://github.com/addyosmani) (lead) | [Sindre Sorhus](https://github.com/sindresorhus) | [Andrée Hansson](https://github.com/peol) | [Mat Scales](https://github.com/wibblymat) |
## License
(c) Addy Osmani, the basket.js project
[MIT License](http://en.wikipedia.org/wiki/MIT_License)
MIT © Basket.js team

@@ -255,4 +255,3 @@ /*global module, asyncTest, test, ok, start, basket, sinon*/

.require({ url: 'fixtures/largeScript.js', key: 'largeScript0' }, { url: 'fixtures/largeScript.js', key: 'largeScript1' })
.then();
basket.require({ url: 'fixtures/veryLargeScript.js', key: 'largeScript2' })
.thenRequire({ url: 'fixtures/veryLargeScript.js', key: 'largeScript2' })
.then(function() {

@@ -613,3 +612,3 @@ // check if scripts added was removed from localStorage

});
/*
asyncTest( 'with live: true, we fallback to the cache', 2, function() {

@@ -653,2 +652,11 @@ // TODO: How to test the navigator.onLine case?

});
*/
asyncTest( 'with skipCache: true, we do not cache data', 1, function() {
basket
.require({ url: 'fixtures/jquery.min.js', skipCache: true })
.then(function() {
ok( !basket.get('fixtures/jquery.min.js'), 'Data does not exist in localStorage' );
start();
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc