You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+22-1Lines changed: 22 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,15 +17,36 @@ $ npm install load-script
17
17
```
18
18
19
19
## API
20
+
`load-script` appends a `script` node to the `<head>` element in the dom.
21
+
22
+
`require('load-script')` returns a function of the following interface: `function(url[, opts][, cb]) {}`
23
+
24
+
### url
25
+
Any url that you would like to load. May be absolute or relative.
26
+
27
+
### [, opts]
28
+
A map of options. Here are the currently supported options:
29
+
30
+
*`async` - A boolean value used for `script.async`. By default this is `true`.
31
+
*`attrs` - A map of attributes to set on the `script` node before appending it to the DOM. By default this is empty.
32
+
*`charset` - A string value used for `script.charset`. By default this is `utf8`.
33
+
*`text` - A string of text to append to the `script` node before it is appended to the DOM. By default this is empty.
34
+
*`type` - A string used for `script.type`. By default this is `text/javascript`.
35
+
36
+
### [, cb]
37
+
A callback function of the following interface: `function(err, script) {}` where `err` is an error if any occurred and `script` is the `script` node that was appended to the DOM.
38
+
39
+
## Example Usage
20
40
21
41
```javascript
22
42
var load =require('load-script')
23
43
24
-
load('foo.js', function (err) {
44
+
load('foo.js', function (err, script) {
25
45
if (err) {
26
46
// print useful message
27
47
}
28
48
else {
49
+
console.log(script.src);// Prints 'foo'.js'
29
50
// use script
30
51
// note that in IE8 and below loading error wouldn't be reported
0 commit comments