Skip to content

Instantly share code, notes, and snippets.

@Rich-Harris
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rich-Harris/9195299 to your computer and use it in GitHub Desktop.
Save Rich-Harris/9195299 to your computer and use it in GitHub Desktop.
AMD loaders that use local resources during optimisation, but CDN resources in production - possible?

So I have an AMD loader, which ingests HTML files that define Ractive.js components (think HTML imports describing Web Components - it's fairly similar in concept). Similar to @jrburke's Element loader. The discussion around the Ractive single-file-components spec is here, if anyone is interested.

The loader itself isn't currently online but will be in the near future.

Here's the issue: we have several different apps sharing a single page (these are interactive components within a news article), several of which use this loader. There's no sense in including Ractive with each optimised build, so in common with other libraries that are shared by several components (e.g. jQuery and d3) it is excluded from the optimised build and served from a CDN.

The problem is that the loader needs Ractive during the optimisation process, to parse the HTML files into a form it can work with. Because of this, the paths config entry for Ractive has to point to a local file - but then the library gets included in the build. Ideally there'd be some way of saying 'use the local file during optimisation, but at runtime use the CDN URL'. As far as I can tell there isn't - but I'd love to be corrected.

Anyone have any ideas for a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment