Did I ask too much?! All I wanted was to load a jQuery plugin from a bookmarklet. Before I could say “CoffeeScript”, found myself mired in the bog that is dynamic script loading.
Why dynamic?
- In our case, using a bookmarklet, so by definition patching an already loaded DOM.
- But even when we control the served HTML, lazy loading makes sense, to both improve performance by letting browser parallelize loading and rendering, to present something earlier, but also for progressive enhancement: selectively load functionality as needed.
Headache
…
“Complete” solutions
- CommonJS (CJS), RequireJS, et al
…
LABjs
…
Example
- Bookmarklet: bootstrapping
- LABjs
- jQuery, but which version?
- Constants: “cached” JSON
- jQuery plugins: replace, qTip2…
- And our own code!
Cake
- coffee2js
- Uglifying
- To combine, or not to combine?
- Deploy?
- Package?
…