I have 2 scripts which should be run with async defer. but the problem is that the 2nd script relies on the first one. js-map-label.js
needs to be run only after googleapis
has been loaded and running. it works 80% of the time with this setup. but sometimes it wouldn't run, so I had to refresh over and over till the js-map-label.js
runs. Is there any way to fix this?
I have these scripts in this order:
...
<script src="https://maps.googleapis.com/maps/api/js?key=__MY_KEY_HERE__...." async defer></script>
<script src="/static/js/js-map-label.js" async defer></script>
...
</body>
It would sometimes raise this error:
js-map-label.js:13 Uncaught ReferenceError: google is not defined
at js-map-label.js:13
at js-map-label.js:16