Enable using this library to pre-load the JSAPISee original GitHub issue
- user visits index route (no map, no JSAPI yet)
- app renders index page, then starts loading JSAPI (
bootstrap()) so that map route loads faster once people go there
- user clicks link to map route
- map route checks if already loaded (
isLoaded()) or loading, if not, load JSAPI. Once JSAPI is loaded, create the map
The only thing new here (when compared to the lazy loading example) is keeping track of the notion that the JSAPI is already in the process of being loaded and providing a hook to do something once it’s done. Currently users can pass a callback, but in a preloading scenario, the context is likely to change between when a user calls
bootstrap()and when they want to actually create a map.
One idea is to expose an
isLoading property and
.on('load', fn)) event. I’m not a real big fan of having both a callback and an event, so if we go this route, may want to deprecate the callback? Not sure.
- Created 7 years ago
- Comments:8 (8 by maintainers)
Top GitHub Comments
First off thanks for putting these libraries up, I’ve just started playing with angular 2 and have been working off this to create a similar implementation bundled in with an angular service.
One possible solution is to check for the existence of the API script tag in
dojoRequire(), and if
window['require'] is undefined, then add an event listener to the script that will execute the callback, like so:
Here’s a sample with some console.logs to demonstrate the order of operations: https://jsfiddle.net/gvaq4tph/5/