Last active
July 28, 2016 13:19
-
-
Save Nitive/b9b92643b832606bca72a7ab0e0ae2d3 to your computer and use it in GitHub Desktop.
Асинхронная подгрузка Яндекс Карт
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <script async src="https://...?lang=ru_RU&load=&onload=_onYandexMapLoaded"></script> | |
// or use module aload instead of async attribute (github.com/pazguille/aload) | |
(function () { | |
var ymapFunctionsStack = []; | |
var ymapsLoaded = false; | |
// random postfix to get uniq function name | |
window._onYandexMapLoaded = function () { | |
ymapsLoaded = true; | |
while (ymapFunctionsStack.length) { | |
ymapFunctionsStack.pop()(); | |
} | |
}; | |
window.ymapsRequire = function (dependencies, callback) { | |
if (ymapsLoaded) { | |
ymaps.modules.require(dependencies, callback); | |
} else { | |
ymapFunctionsStack.push(function () { | |
ymaps.modules.require(dependencies, callback); | |
}); | |
} | |
}; | |
}()); | |
// Usage example: | |
// ymapsRequire(['Map', 'Placemark'], (Map, Placemark) => { | |
// console.log('loaded', Map, Placemark) | |
// }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For common.js