Search code examples
ecmascript-6jspmsystemjs

How to use System.js with CDN and local fallback?


I ran jspm install angular and it installed it locally to my jspm_packages folder.

From code, I use regular ES6 imports like import angular from 'angular'.

What do I need to do in order to load angular from a CDN and fallback to a local version if the CDN is unavailable?


Solution

  • You can have different config.js files for development and production, where the production one gets angular from a CDN while development gets it locally. However, there is not (as far as I know) currently a way to have SystemJS try one source, then if that fails fallback to another source.

    System.config({
        "map": {
            "jquery": "https://code.jquery.com/jquery-2.1.4.js"
        }
    });