Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Any url that you would like to load. May be absolute or relative.
A map of options. Here are the currently supported options:

* `async` - A boolean value used for `script.async`. By default this is `true`.
* `defer` - A boolean value used for `script.defer`. By default this is `true`.
* `attrs` - A map of attributes to set on the `script` node before appending it to the DOM. By default this is empty.
* `charset` - A string value used for `script.charset`. By default this is `utf8`.
* `text` - A string of text to append to the `script` node before it is appended to the DOM. By default this is empty.
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = function load (src, opts, cb) {
script.type = opts.type || 'text/javascript'
script.charset = opts.charset || 'utf8';
script.async = 'async' in opts ? !!opts.async : true
script.defer = 'defer' in opts ? !!opts.defer : true
script.src = src

if (opts.attrs) {
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ test('opts.async', function(done) {
})
});

test('opts.defer.true', function(done) {
load('test/hello.js', {defer: true}, function(err, script) {
assert.ifError(err);
assert.equal(script.defer, true);
done();
})
});

test('opts.defer.false', function(done) {
load('test/hello.js', {defer: false}, function(err, script) {
assert.ifError(err);
assert.equal(script.defer, false);
done();
})
});

test('opts.attrs', function(done) {
load('test/hello.js', {attrs: {foo: 'boo'}}, function(err, script) {
assert.ifError(err);
Expand Down