Socket
Socket
Sign inDemoInstall

loadjs

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loadjs - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

1

AUTHORS.txt

@@ -6,1 +6,2 @@ Authors ordered by first contribution.

Ryan Burke https://github.com/codeburke
Todd Williams https://github.com/toddw

2

bower.json
{
"name": "loadjs",
"version": "3.1.0",
"version": "3.2.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "authors": [

# LoadJS Changelog
## 3.2.0 - December 11, 2016
* Added `before` callback hook to modify script/link elements before adding
them to the DOM
## 3.1.0 - December 9, 2016

@@ -4,0 +9,0 @@

@@ -87,2 +87,3 @@ loadjs = (function () {

maxTries = (args.numRetries || 0) + 1,
beforeCallbackFn = (args.before || devnull),
isCss,

@@ -136,2 +137,5 @@ e;

};
// execute before callback
beforeCallbackFn(path, e);

@@ -138,0 +142,0 @@ // add to document

@@ -1,1 +0,1 @@

loadjs=function(){function n(n,e){n=n.push?n:[n];var t,r,o,i,c=[],f=n.length,h=f;for(t=function(n,t){t.length&&c.push(n),h--,h||e(c)};f--;)r=n[f],o=u[r],o?t(r,o):(i=s[r]=s[r]||[],i.push(t))}function e(n,e){if(n){var t=s[n];if(u[n]=e,t)for(;t.length;)t[0](n,e),t.splice(0,1)}}function t(n,e,r,o){var i,c,u=document,s=r.async,f=(r.numRetries||0)+1;o=o||0,/\.css$/.test(n)?(i=!0,c=u.createElement("link"),c.rel="stylesheet",c.href=n):(c=u.createElement("script"),c.src=n,c.async=void 0===s||s),c.onload=c.onerror=c.onbeforeload=function(u){var s=u.type[0];if(i&&"hideFocus"in c)try{c.sheet.cssText.length||(s="e")}catch(n){s="e"}return"e"==s&&(o+=1,o<f)?t(n,e,r,o):void e(n,s,u.defaultPrevented)},u.head.appendChild(c)}function r(n,e,r){n=n.push?n:[n];var o,i,c=n.length,u=c,s=[];for(o=function(n,t,r){if("e"==t&&s.push(n),"b"==t){if(!r)return;s.push(n)}c--,c||e(s)},i=0;i<u;i++)t(n[i],o,r)}function o(n,t,o){var u,s;if(t&&t.trim&&(u=t),s=(u?o:t)||{},u){if(u in c)throw new Error("LoadJS");c[u]=!0}r(n,function(n){n.length?(s.error||i)(n):(s.success||i)(),e(u,n)},s)}var i=function(){},c={},u={},s={};return o.ready=function(e,t){return n(e,function(n){n.length?(t.error||i)(n):(t.success||i)()}),o},o.done=function(n){e(n,[])},o}();
loadjs=function(){function e(e,n){e=e.push?e:[e];var t,r,o,i,c=[],s=e.length,h=s;for(t=function(e,t){t.length&&c.push(e),h--,h||n(c)};s--;)r=e[s],o=u[r],o?t(r,o):(i=f[r]=f[r]||[],i.push(t))}function n(e,n){if(e){var t=f[e];if(u[e]=n,t)for(;t.length;)t[0](e,n),t.splice(0,1)}}function t(e,n,r,o){var c,u,f=document,s=r.async,h=(r.numRetries||0)+1,a=r.before||i;o=o||0,/\.css$/.test(e)?(c=!0,u=f.createElement("link"),u.rel="stylesheet",u.href=e):(u=f.createElement("script"),u.src=e,u.async=void 0===s||s),u.onload=u.onerror=u.onbeforeload=function(i){var f=i.type[0];if(c&&"hideFocus"in u)try{u.sheet.cssText.length||(f="e")}catch(e){f="e"}return"e"==f&&(o+=1,o<h)?t(e,n,r,o):void n(e,f,i.defaultPrevented)},a(e,u),f.head.appendChild(u)}function r(e,n,r){e=e.push?e:[e];var o,i,c=e.length,u=c,f=[];for(o=function(e,t,r){if("e"==t&&f.push(e),"b"==t){if(!r)return;f.push(e)}c--,c||n(f)},i=0;i<u;i++)t(e[i],o,r)}function o(e,t,o){var u,f;if(t&&t.trim&&(u=t),f=(u?o:t)||{},u){if(u in c)throw new Error("LoadJS");c[u]=!0}r(e,function(e){e.length?(f.error||i)(e):(f.success||i)(),n(u,e)},f)}var i=function(){},c={},u={},f={};return o.ready=function(n,t){return e(n,function(e){e.length?(t.error||i)(e):(t.success||i)()}),o},o.done=function(e){n(e,[])},o}();

@@ -95,2 +95,3 @@ (function(root, factory) {

maxTries = (args.numRetries || 0) + 1,
beforeCallbackFn = (args.before || devnull),
isCss,

@@ -144,2 +145,5 @@ e;

};
// execute before callback
beforeCallbackFn(path, e);

@@ -146,0 +150,0 @@ // add to document

@@ -87,2 +87,3 @@ loadjs = (function () {

maxTries = (args.numRetries || 0) + 1,
beforeCallbackFn = (args.before || devnull),
isCss,

@@ -136,2 +137,5 @@ e;

};
// execute before callback
beforeCallbackFn(path, e);

@@ -138,0 +142,0 @@ // add to document

@@ -1,1 +0,1 @@

loadjs=function(){function n(n,e){n=n.push?n:[n];var t,r,o,i,c=[],f=n.length,h=f;for(t=function(n,t){t.length&&c.push(n),h--,h||e(c)};f--;)r=n[f],o=u[r],o?t(r,o):(i=s[r]=s[r]||[],i.push(t))}function e(n,e){if(n){var t=s[n];if(u[n]=e,t)for(;t.length;)t[0](n,e),t.splice(0,1)}}function t(n,e,r,o){var i,c,u=document,s=r.async,f=(r.numRetries||0)+1;o=o||0,/\.css$/.test(n)?(i=!0,c=u.createElement("link"),c.rel="stylesheet",c.href=n):(c=u.createElement("script"),c.src=n,c.async=void 0===s||s),c.onload=c.onerror=c.onbeforeload=function(u){var s=u.type[0];if(i&&"hideFocus"in c)try{c.sheet.cssText.length||(s="e")}catch(n){s="e"}return"e"==s&&(o+=1,o<f)?t(n,e,r,o):void e(n,s,u.defaultPrevented)},u.head.appendChild(c)}function r(n,e,r){n=n.push?n:[n];var o,i,c=n.length,u=c,s=[];for(o=function(n,t,r){if("e"==t&&s.push(n),"b"==t){if(!r)return;s.push(n)}c--,c||e(s)},i=0;i<u;i++)t(n[i],o,r)}function o(n,t,o){var u,s;if(t&&t.trim&&(u=t),s=(u?o:t)||{},u){if(u in c)throw new Error("LoadJS");c[u]=!0}r(n,function(n){n.length?(s.error||i)(n):(s.success||i)(),e(u,n)},s)}var i=function(){},c={},u={},s={};return o.ready=function(e,t){return n(e,function(n){n.length?(t.error||i)(n):(t.success||i)()}),o},o.done=function(n){e(n,[])},o}();
loadjs=function(){function e(e,n){e=e.push?e:[e];var t,r,o,i,c=[],s=e.length,h=s;for(t=function(e,t){t.length&&c.push(e),h--,h||n(c)};s--;)r=e[s],o=u[r],o?t(r,o):(i=f[r]=f[r]||[],i.push(t))}function n(e,n){if(e){var t=f[e];if(u[e]=n,t)for(;t.length;)t[0](e,n),t.splice(0,1)}}function t(e,n,r,o){var c,u,f=document,s=r.async,h=(r.numRetries||0)+1,a=r.before||i;o=o||0,/\.css$/.test(e)?(c=!0,u=f.createElement("link"),u.rel="stylesheet",u.href=e):(u=f.createElement("script"),u.src=e,u.async=void 0===s||s),u.onload=u.onerror=u.onbeforeload=function(i){var f=i.type[0];if(c&&"hideFocus"in u)try{u.sheet.cssText.length||(f="e")}catch(e){f="e"}return"e"==f&&(o+=1,o<h)?t(e,n,r,o):void n(e,f,i.defaultPrevented)},a(e,u),f.head.appendChild(u)}function r(e,n,r){e=e.push?e:[e];var o,i,c=e.length,u=c,f=[];for(o=function(e,t,r){if("e"==t&&f.push(e),"b"==t){if(!r)return;f.push(e)}c--,c||n(f)},i=0;i<u;i++)t(e[i],o,r)}function o(e,t,o){var u,f;if(t&&t.trim&&(u=t),f=(u?o:t)||{},u){if(u in c)throw new Error("LoadJS");c[u]=!0}r(e,function(e){e.length?(f.error||i)(e):(f.success||i)(),n(u,e)},f)}var i=function(){},c={},u={},f={};return o.ready=function(n,t){return e(n,function(e){e.length?(t.error||i)(e):(t.success||i)()}),o},o.done=function(e){n(e,[])},o}();
{
"name": "loadjs",
"version": "3.1.0",
"version": "3.2.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Tiny async loader for modern browsers",

@@ -5,3 +5,3 @@ # LoadJS

LoadJS is a tiny async loader for modern browsers (696 bytes).
LoadJS is a tiny async loader for modern browsers (710 bytes).

@@ -15,3 +15,3 @@ [![Dependency Status](https://david-dm.org/muicss/loadjs.svg)](https://david-dm.org/muicss/loadjs)

LoadJS is based on the excellent <a href="https://github.com/ded/script.js">$script</a> library by <a href="https://github.com/ded">Dustin Diaz</a>. We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 696 bytes (minified + gzipped).
LoadJS is based on the excellent <a href="https://github.com/ded/script.js">$script</a> library by <a href="https://github.com/ded">Dustin Diaz</a>. We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 710 bytes (minified + gzipped).

@@ -131,2 +131,10 @@ Here's an example of what you can do with LoadJS:

1. Execute a callback before script tags are embedded
```javascript
loadjs(['/path/to/foo.js', '/path/to/bar.js'], {
before: function(path, scriptEl) { /* called for each script node before embedded */ }
});
```
1. Execute a callback after bundle finishes loading

@@ -133,0 +141,0 @@

@@ -86,2 +86,3 @@ /**

maxTries = (args.numRetries || 0) + 1,
beforeCallbackFn = (args.before || devnull),
isCss,

@@ -135,2 +136,5 @@ e;

};
// execute before callback
beforeCallbackFn(path, e);

@@ -137,0 +141,0 @@ // add to document

@@ -87,2 +87,3 @@ loadjs = (function () {

maxTries = (args.numRetries || 0) + 1,
beforeCallbackFn = (args.before || devnull),
isCss,

@@ -136,2 +137,5 @@ e;

};
// execute before callback
beforeCallbackFn(path, e);

@@ -138,0 +142,0 @@ // add to document

@@ -1,1 +0,1 @@

loadjs=function(){function n(n,e){n=n.push?n:[n];var t,r,o,i,c=[],f=n.length,h=f;for(t=function(n,t){t.length&&c.push(n),h--,h||e(c)};f--;)r=n[f],o=u[r],o?t(r,o):(i=s[r]=s[r]||[],i.push(t))}function e(n,e){if(n){var t=s[n];if(u[n]=e,t)for(;t.length;)t[0](n,e),t.splice(0,1)}}function t(n,e,r,o){var i,c,u=document,s=r.async,f=(r.numRetries||0)+1;o=o||0,/\.css$/.test(n)?(i=!0,c=u.createElement("link"),c.rel="stylesheet",c.href=n):(c=u.createElement("script"),c.src=n,c.async=void 0===s||s),c.onload=c.onerror=c.onbeforeload=function(u){var s=u.type[0];if(i&&"hideFocus"in c)try{c.sheet.cssText.length||(s="e")}catch(n){s="e"}return"e"==s&&(o+=1,o<f)?t(n,e,r,o):void e(n,s,u.defaultPrevented)},u.head.appendChild(c)}function r(n,e,r){n=n.push?n:[n];var o,i,c=n.length,u=c,s=[];for(o=function(n,t,r){if("e"==t&&s.push(n),"b"==t){if(!r)return;s.push(n)}c--,c||e(s)},i=0;i<u;i++)t(n[i],o,r)}function o(n,t,o){var u,s;if(t&&t.trim&&(u=t),s=(u?o:t)||{},u){if(u in c)throw new Error("LoadJS");c[u]=!0}r(n,function(n){n.length?(s.error||i)(n):(s.success||i)(),e(u,n)},s)}var i=function(){},c={},u={},s={};return o.ready=function(e,t){return n(e,function(n){n.length?(t.error||i)(n):(t.success||i)()}),o},o.done=function(n){e(n,[])},o}();
loadjs=function(){function e(e,n){e=e.push?e:[e];var t,r,o,i,c=[],s=e.length,h=s;for(t=function(e,t){t.length&&c.push(e),h--,h||n(c)};s--;)r=e[s],o=u[r],o?t(r,o):(i=f[r]=f[r]||[],i.push(t))}function n(e,n){if(e){var t=f[e];if(u[e]=n,t)for(;t.length;)t[0](e,n),t.splice(0,1)}}function t(e,n,r,o){var c,u,f=document,s=r.async,h=(r.numRetries||0)+1,a=r.before||i;o=o||0,/\.css$/.test(e)?(c=!0,u=f.createElement("link"),u.rel="stylesheet",u.href=e):(u=f.createElement("script"),u.src=e,u.async=void 0===s||s),u.onload=u.onerror=u.onbeforeload=function(i){var f=i.type[0];if(c&&"hideFocus"in u)try{u.sheet.cssText.length||(f="e")}catch(e){f="e"}return"e"==f&&(o+=1,o<h)?t(e,n,r,o):void n(e,f,i.defaultPrevented)},a(e,u),f.head.appendChild(u)}function r(e,n,r){e=e.push?e:[e];var o,i,c=e.length,u=c,f=[];for(o=function(e,t,r){if("e"==t&&f.push(e),"b"==t){if(!r)return;f.push(e)}c--,c||n(f)},i=0;i<u;i++)t(e[i],o,r)}function o(e,t,o){var u,f;if(t&&t.trim&&(u=t),f=(u?o:t)||{},u){if(u in c)throw new Error("LoadJS");c[u]=!0}r(e,function(e){e.length?(f.error||i)(e):(f.success||i)(),n(u,e)},f)}var i=function(){},c={},u={},f={};return o.ready=function(n,t){return e(n,function(e){e.length?(t.error||i)(e):(t.success||i)()}),o},o.done=function(e){n(e,[])},o}();

@@ -50,2 +50,30 @@ /**

});
it('should call before callback before embedding into document', function(done) {
var scriptTags = [];
loadjs(['assets/file1.js', 'assets/file2.js'], {
before: function(path, el) {
scriptTags.push({
path: path,
el: el
});
// add cross origin script for file2
if (path === 'assets/file2.js') {
el.crossOrigin = 'anonymous';
}
},
success: function () {
assert.equal(scriptTags[0].path, 'assets/file1.js');
assert.equal(scriptTags[1].path, 'assets/file2.js');
assert.equal(scriptTags[0].el.crossOrigin, undefined);
assert.equal(scriptTags[1].el.crossOrigin, 'anonymous');
done();
}
});
});

@@ -52,0 +80,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc