DynoSRC/dynosrc — pull request #10 by diurnalist (2013-12-19 17:56:03+00:00)
Title: Breaking core JS into smaller auto-loaded plugins

A step towards making DynoSRC eat its own dog food.

### Client side
The main client JS has been broken into 3 subcomponents:

- dynoSrc-core.js: contains the localStorage drive and a simplified
`add`/`load` interface to either add modules to the cache/manifest, or
load them from the cache. Exposes hooks for 'update' and 'destroy' so
you can either listen when assets are updated, or when the entire
library is torn down (to allow plugins to perform cleanup, mostly)

- dynoSrc-cookie.js: pretty simple, primes the manifest by looking at
the `_ds` cookie on load, if present. Also updates this cookie on the
client whenever an asset is added to the manifest. Also clears the
cookie on destroy.

- dynoSrc-diff.js: adds support for detecting contextual diffs and doing
the merge before adding the final asset into local storage

The core.js weighs in at about 1.25K uncompressed, which amounts to
about 600bytes with gzip according to Closure Compiler. I haven't added
support for automatic minification when the core library is inlined
into the output HTML. It could probably be trimmed up a bit more, but I
wanted to wait to see you y'all felt about its current state.

The other libraries, if it matters, are about the same size. But the
main thing is, they're totally optional.

### Server side
The dynosrc npm module now exposes an extra `getClientLib` function,
which allows the developer to choose where to inline our special script.
It has to be done in this way b/c the script is actually templated a bit
with dynosrc config options (like, which plugins to load on init).

Also added a `core` source that is used to resolve the dynosrc core JS
assets like the 'cookie' and 'diff' submodules. The cool part is they
are automatically tracked against the package.json HEAD, so whenever we
re-publish and include a fix to the JS submodules, clients will start
getting those new assets right away :)