Script Loading

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?

  1. In our case, using a bookmarklet, so by definition patching an already loaded DOM.
  2. 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

  1. CommonJS (CJS), RequireJS, et al

LABjs

Example

  1. Bookmarklet: bootstrapping
  2. LABjs
  3. jQuery, but which version?
  4. Constants: “cached” JSON
  5. jQuery plugins: replace, qTip2…
  6. And our own code!

Cake

  1. coffee2js
  2. Uglifying
  3. To combine, or not to combine?
  4. Deploy?
  5. Package?



Comments are closed.