このコードは、urlとオプションのコールバックをとる遅延関数を提供します。 ページのレンダリングをブロックせずにスクリプトを非同期に読み込みます。 私はプロテクションを入れているので、同じscritpを2回ロードしないので、好きなだけ何度でも呼び出すことができます。
defer = (function() {
var urls = [];
return function (url, callback) {
var inc;
if (url && urls.indexOf(url) === -1) {
inc = document.createElement('script');
inc.async = true;
inc.src = url;
inc.onload = callback || function() {};
document.getElementsByTagName('head')[0].appendChild(inc);
}
}
}());
defer('http://maps.google.com/maps/api/js?sensor=false');
これは、非同期読み込みに失敗しない任意の外部javascriptで機能します。
「非同期」セクションがドキュメントから削除されているようです... [このページ](https://google-developers.appspot.com/maps/documentation/javascript/examples/map-simple-非同期)、ソースにはGoogle Mapsライブラリの非同期読み込みのサンプルが含まれています –