Show HN: LoadJS – A tiny async loader for modern browsers (github.com) 25 points by andres 10y ago ↗ HN
[–] brudgers 10y ago ↗ Curious as to how 84 bytes were shaved since the previous posting. https://news.ycombinator.com/item?id=9941182 [–] andres 10y ago ↗ Here are some of the changes: * Replaced for-loops with while-loops [1] * Removed un-necessary code in the script loading function [2][3] * Removed setTimeout wrapper [4][5] [1] https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L...[2] https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L...[3] https://github.com/muicss/loadjs/blob/8d380e1f6c2af431b08088...[4] https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L...[5] https://github.com/muicss/loadjs/blob/8d380e1f6c2af431b08088...
[–] andres 10y ago ↗ Here are some of the changes: * Replaced for-loops with while-loops [1] * Removed un-necessary code in the script loading function [2][3] * Removed setTimeout wrapper [4][5] [1] https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L...[2] https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L...[3] https://github.com/muicss/loadjs/blob/8d380e1f6c2af431b08088...[4] https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L...[5] https://github.com/muicss/loadjs/blob/8d380e1f6c2af431b08088...
[–] teknologist 10y ago ↗ For wider browser support I've always relied on LABjs. It's been around for ages and has to be among the most stable JS libraries out there despite having to deal with all those browser quirks.http://labjs.com/
[–] fbdjfhhcbd 10y ago ↗ For what purpose?Just stop layering bloat. [–] King-Aaron 10y ago ↗ But what if you want to load four hundred dependant scripts on each pageload? :( [–] romanovcode 10y ago ↗ 1. If you need four hundred dependant scripts to load a page you're doing something wrong.2. Why can't you just use <script async src="/js/script.js"></script> and be done with it in the first place? [–] michaelmior 10y ago ↗ Because async doesn't do what you think it does.https://www.stevesouders.com/blog/2012/01/13/javascript-perf...
[–] King-Aaron 10y ago ↗ But what if you want to load four hundred dependant scripts on each pageload? :( [–] romanovcode 10y ago ↗ 1. If you need four hundred dependant scripts to load a page you're doing something wrong.2. Why can't you just use <script async src="/js/script.js"></script> and be done with it in the first place? [–] michaelmior 10y ago ↗ Because async doesn't do what you think it does.https://www.stevesouders.com/blog/2012/01/13/javascript-perf...
[–] romanovcode 10y ago ↗ 1. If you need four hundred dependant scripts to load a page you're doing something wrong.2. Why can't you just use <script async src="/js/script.js"></script> and be done with it in the first place? [–] michaelmior 10y ago ↗ Because async doesn't do what you think it does.https://www.stevesouders.com/blog/2012/01/13/javascript-perf...
[–] michaelmior 10y ago ↗ Because async doesn't do what you think it does.https://www.stevesouders.com/blog/2012/01/13/javascript-perf...
[–] andres 10y ago ↗ I just shaved off another 3 bytes so LoadJS is now 503 bytes (minified + gzipped). HN - If you see a way to get below 500 bytes please let me know!https://github.com/muicss/loadjs/blob/master/src/loadjs.js [–] barsonme 10y ago ↗ Using ES5 features? Because arrow functions would make it smaller.Also using an if/else instead of continue saves 4 bytes.Using arrow functions shaves off another 2 bytes.(Gzipped that's 489 bytes.)[0][0] - https://closure-compiler.appspot.com/code/jscde34e44897623a8... [–] andres 10y ago ↗ That's a good suggestion but it looks like the minifier removes "continue" automatically: https://raw.githubusercontent.com/muicss/loadjs/master/dist/...Arrow functions would be great but then we'd have to drop support for browsers that don't support ES6. [–] barsonme 10y ago ↗ It seems running your original code through the closure compiler shaves it down to 488 max.The closure compiler doesn't respect arrow functions, so I'm assuming that'd have to be changed manually. [–] [deleted] 10y ago ↗ (comment deleted)
[–] barsonme 10y ago ↗ Using ES5 features? Because arrow functions would make it smaller.Also using an if/else instead of continue saves 4 bytes.Using arrow functions shaves off another 2 bytes.(Gzipped that's 489 bytes.)[0][0] - https://closure-compiler.appspot.com/code/jscde34e44897623a8... [–] andres 10y ago ↗ That's a good suggestion but it looks like the minifier removes "continue" automatically: https://raw.githubusercontent.com/muicss/loadjs/master/dist/...Arrow functions would be great but then we'd have to drop support for browsers that don't support ES6. [–] barsonme 10y ago ↗ It seems running your original code through the closure compiler shaves it down to 488 max.The closure compiler doesn't respect arrow functions, so I'm assuming that'd have to be changed manually. [–] [deleted] 10y ago ↗ (comment deleted)
[–] andres 10y ago ↗ That's a good suggestion but it looks like the minifier removes "continue" automatically: https://raw.githubusercontent.com/muicss/loadjs/master/dist/...Arrow functions would be great but then we'd have to drop support for browsers that don't support ES6. [–] barsonme 10y ago ↗ It seems running your original code through the closure compiler shaves it down to 488 max.The closure compiler doesn't respect arrow functions, so I'm assuming that'd have to be changed manually.
[–] barsonme 10y ago ↗ It seems running your original code through the closure compiler shaves it down to 488 max.The closure compiler doesn't respect arrow functions, so I'm assuming that'd have to be changed manually.
[–] sunrising 10y ago ↗ check out https://github.com/sun2rise/dysel too [–] andres 10y ago ↗ How does dysel do sequential loading? Dynamically loaded script tags default to async=true so I think this code loads/executes scripts asynchronously:https://github.com/sun2rise/dysel/blob/master/dist/dysel.js#...
[–] andres 10y ago ↗ How does dysel do sequential loading? Dynamically loaded script tags default to async=true so I think this code loads/executes scripts asynchronously:https://github.com/sun2rise/dysel/blob/master/dist/dysel.js#...
15 comments
[ 4.4 ms ] story [ 43.5 ms ] thread[2] https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L...
[3] https://github.com/muicss/loadjs/blob/8d380e1f6c2af431b08088...
[4] https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L...
[5] https://github.com/muicss/loadjs/blob/8d380e1f6c2af431b08088...
http://labjs.com/
Just stop layering bloat.
2. Why can't you just use <script async src="/js/script.js"></script> and be done with it in the first place?
https://www.stevesouders.com/blog/2012/01/13/javascript-perf...
https://github.com/muicss/loadjs/blob/master/src/loadjs.js
Also using an if/else instead of continue saves 4 bytes.
Using arrow functions shaves off another 2 bytes.
(Gzipped that's 489 bytes.)[0]
[0] - https://closure-compiler.appspot.com/code/jscde34e44897623a8...
Arrow functions would be great but then we'd have to drop support for browsers that don't support ES6.
The closure compiler doesn't respect arrow functions, so I'm assuming that'd have to be changed manually.
https://github.com/sun2rise/dysel/blob/master/dist/dysel.js#...