But what happen if, you launch your app offline and try later to use the googlemaps feature online?
It won’t work, right.
How to ensure the external lib is loaded when I call this feature?
Last few years Google Maps V3 is a standard. It’s a stable well done project.
Script done today will usually work with code written few years ago. This is because most of that code is backward compatible. Even if Google decide to deprecate some part of that code you will be give one year (usually) to update your code.
Also, Google will never change backend resources and service without giving you enough time to adapt.
Another thing, changes to Google Maps js file are no more different than changes to your code. If they occur, you will just create and deploy a new version of your application.
@Gajotres is right, you should not be writing any code that includes the script and provides callbacks etc.
Include the library directly into your app, it will be easier to cache and if you are offline you should be wrapping your “online only” features to protect the user from encountering errors anyways.
As for risks involved in including it as a library, it’s far less riskier than including it as an external file where you don’t have direct control over the resources and what api calls are available etc.
Google like most companies always provide a notice period before issuing breaking changes but still support legacy code giving you time to update your app, which you should be doing anyways.
I have the same problem in an app I am developing. I can include google maps locally however I also use Stripe.js for payments (https://js.stripe.com/v2/). Stripe will not allow me to host their script locally.
Host locally everything you can, this way you’ll prevent data traffic every time application is initialized. Plus your application will also work in the offline mode.
If something requires a remote use, you can’t do much against it. Let it be, just make sure you have a fallback if an application can’t access the internet. For example some kind of warning.
Even after plenty of Googling around it wasn’t clear to me how to “embed” an offline version of the Google Maps scripts in my app, so now I’m using your script to load the script “on demand”.
So, either within my “run” function (if the network is available when the application starts), or just before I need to display a map.
Well the offline idea will not work for things like stripe.js. Since stripe.js needs to be loaded off a https server.
I tried loading a payment page via ionicPopup and ionicModal but my external JS doesn’t fire, even if wrapped within window.onload().