diff --git a/Readme.md b/Readme.md index 8641105..8b6fe60 100644 --- a/Readme.md +++ b/Readme.md @@ -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. diff --git a/index.js b/index.js index 667b919..4602c39 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/test/index.js b/test/index.js index a620764..70258a2 100644 --- a/test/index.js +++ b/test/index.js @@ -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);