https://github.com/intermine/intermine-api-loader
Simplify loading of JS and CSS dependencies
https://github.com/intermine/intermine-api-loader
Last synced: 14 days ago
JSON representation
Simplify loading of JS and CSS dependencies
- Host: GitHub
- URL: https://github.com/intermine/intermine-api-loader
- Owner: intermine
- Created: 2012-05-01T17:10:43.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-05-29T12:49:43.000Z (over 12 years ago)
- Last Synced: 2025-01-19T18:52:38.553Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 491 KB
- Stars: 1
- Watchers: 4
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#InterMine API Loader
Simplify loading of JS and CSS dependencies.
[ ](https://www.codeship.io/projects/3085)
## Quickstart
Include `intermine.api.js` on a page then resolve dependencies as follows:
```javascript
intermine.load({
'js': {
'JSON': {
'path': 'http://cdn.intermine.org/js/json3/3.2.2/json3.min.js'
},
'setImmediate': {
'path': 'http://cdn.intermine.org/js/setImmediate/1.0.1/setImmediate.min.js'
},
'example': {
'path': 'http://',
'test': function() {
return true;
}
},
'async': {
'path': 'http://cdn.intermine.org/js/async/0.2.6/async.min.js',
'depends': ['setImmediate']
},
'jQuery': {
'path': 'http://cdn.intermine.org/js/jquery/1.8.2/jquery.min.js',
'depends': ['JSON']
},
'_': {
'path': 'http://cdn.intermine.org/js/underscore.js/1.3.3/underscore-min.js',
'depends': ['JSON']
},
'Backbone': {
'path': 'http://cdn.intermine.org/js/backbone.js/0.9.2/backbone-min.js',
'depends': ['jQuery', '_']
}
}
});
```
## Build your Own
```bash
$ npm install
$ make build
```
## Test in CLI
```bash
$ npm install
$ make test
```
## Spec
1. Each dependency to load is grouped under either a `css` or `js` key.
2. A dependency is loaded only if it does not exist on the page already. There are two ways to determine that:
1. Check the name key of the library as to whether or not it is exposed on the `window` object.
1. If a `test` function is provided, run it and continue only if we get `false` back.
3. URL to the dependency is defined under the `path` key.
4. A dependency will be resolved only after all dependencies are met which is defined in an Array under `depends` key.
5. If two requests to load dependency X come at the same time we make only one load and use cache for the second.
6. CSS is a bit random so we just load whatever you ask for not waiting for anything.
7. Keys `load` and `loader` are taken over by us on the `intermine` namespace.
8. **The last parameter of `load` is a callback. Use it, it might respond with an error.**