Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wankdanker/jsinclude
Load js and css files programatically in the browser at run-time.
https://github.com/wankdanker/jsinclude
Last synced: 14 days ago
JSON representation
Load js and css files programatically in the browser at run-time.
- Host: GitHub
- URL: https://github.com/wankdanker/jsinclude
- Owner: wankdanker
- Created: 2015-02-24T17:05:28.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-08T17:33:37.000Z (over 8 years ago)
- Last Synced: 2024-11-06T01:17:19.997Z (2 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
jsinclude
---------Programmatically include JavaScript and CSS files in the browser at runtime.
example
-------```html
include.once("/js/jquery.js", function () {
console.log('jquery is loaded');
});include.css("/css/jquery-ui.css");
include(function () {
console.log('all includes are loaded');
});
Hello
```
api
---### include(path [, charset] [, callback])
Load a script referenced by `path` and call the optional callback function when it has been loaded.
If a string valued charset is passed as the second argument, then the charset attribute will be set
on the script element.### include(callback)
Call `callback` once all pending include files have been loaded.
### include.once(path [,charset] [, callback])
Load a script referenced by `path` at most one time and call the optional callback function when it has been loaded.
If a string valued charset is passed as the second argument, then the charset attribute will be set
on the script element.Callback is still called if the script has already been loaded one or more times.
* **path** : (required) path to the javascript file to load
* **callback** : (optional) callback function which is called once the script referenced by `path` has been loaded.### include.css(path [, options])
Load a stylesheet referenced by `path`.
* **path** : (required) path the css file to load
* **options** : (optional)
* **prepend** : insert the css file before all other stylesheets### include.pathAppend
`pathAppend` is a configuration option that is appended to each `path`.
If `pathAppend` is a function, it is called with `path` as its only argument. The return value should be a string to append to `path`.
Example using a string value:
```js
var package = require('./package.json');include.pathAppend = 'v=' + package.version;
```Example using a function:
```js
var package = require('./package.json');include.pathAppend = function (path) {
if (~path.indexOf('mydomain.com')) {
return 'v=' + package.version;
}
else return '';
};
```License
-------MIT