programsam / binkjs

Music archival site BINK, rewritten as a Node.js express app
0 stars 1 forks source link

Google Map Loads Multiple Times #81

Closed programsam closed 6 years ago

programsam commented 6 years ago

jQuery.loadScript() has some sort of a caching function for this, yeah?

programsam commented 6 years ago

Yeah it has a caching function but that wasn't the problem.

Even when it was cached, it was being told to load it multiple times. Multiple instances in the this object (which I think is the same as the window object). So I determined a way to check if it had been initialized/instantiated:

if (this.hasOwnProperty('google') && google.hasOwnProperty('maps'))

If it's defined, then we don't do a getScript at all. If not defined, then there will be no exception thrown, but it'll go load the script into the DOM so that the callback function can instantiate it.