Skip to content

Instantly share code, notes, and snippets.

@40thieves
Created May 19, 2015 20:55
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 40thieves/b3078a98be7306cb8090 to your computer and use it in GitHub Desktop.
Save 40thieves/b3078a98be7306cb8090 to your computer and use it in GitHub Desktop.
System.js async loader plugin

Usage

To asynchronously load Google maps:

config.js:

System.config({
	"paths": {
		"maps": "google-maps-url"
	}
});

bootstrap.js:

import 'maps!async';

Note: The google global won't be available until it calls a callback included in the URL.

Thanks

All the heavy lifting done in this thread. so all credit goes to them.

License

MIT

var inject = (src) => {
var script, target;
// Create script> linking to async source
script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = src;
// Injects as first <script>
target = document.getElementsByTagName('script')[0];
target.parentNode.insertBefore(script, target);
};
export var fetch = (load) => {
inject(load.address);
// Required to return a string, we're faking that we fetched a file and now we're returning it to SystemJS
return '';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment