Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazily load google map API #66

Open
mike-north opened this issue Jul 20, 2016 · 6 comments
Open

Lazily load google map API #66

mike-north opened this issue Jul 20, 2016 · 6 comments

Comments

@mike-north
Copy link
Contributor

In one of my apps, I only need the google maps API on a few pages. It would be great to not pay the overhead of loading the API unless (and until) it's really necessary.

This would entail making a few things "promise aware" because there's the possibility that the google.* stuff hasn't been loaded yet, and will need to be fetched "just in time".

@steveszc
Copy link
Collaborator

I just opened PR #67 that adds an 'exclude' option to the addon config that prevents the addon from adding the Google Maps API script to the app's index.html. This would give you the opportunity to handle loading of the Google Maps API on your own terms.

@asennikov
Copy link
Owner

Hey @mike-north, what do you think about that addition by @steveszc? Does it solve your issue?

@mike-north
Copy link
Contributor Author

@asennikov - it does, in a sort of DIY sense (the user could explicitly load it before they need it), but an even better solution would be promise-driven, where the script is loaded "just in time" by a service or something. This way, consumers don't need to do any explicit loading, and they don't need to keep track of whether the script has already been loaded or not

@GCheung55
Copy link

This would also be helpful for localization. User locale preferences are determined after login, which then the API script could be loaded with the appropriate language/region.

@EstesE
Copy link
Contributor

EstesE commented May 14, 2021

If I set 'exclude' to true how would I go about loading the Google Maps API manually?

@steveszc
Copy link
Collaborator

If I set 'exclude' to true how would I go about loading the Google Maps API manually?

Totally up to you. You could drop a script tag in your index.html, or you could dynamically create a script tag and insert it into the document when a route is visited or a component is rendered.

Here's an example of how you could dynamically load it.
https://github.com/sandydoo/ember-google-maps/blob/main/addon/services/google-maps-api.js

Worth mentioning that this repo is more or less in maintenance mode. I'd suggest you use https://github.com/sandydoo/ember-google-maps if you have the flexibility to switch.

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

No branches or pull requests

5 participants