{"id":5320,"date":"2011-03-02T23:20:44","date_gmt":"2011-03-02T14:20:44","guid":{"rendered":"http:\/\/fukata.org\/?p=5320"},"modified":"2017-08-11T22:58:49","modified_gmt":"2017-08-11T22:58:49","slug":"load-sync-multi-remote-javascript","status":"publish","type":"post","link":"https:\/\/blog.fukata.org\/archives\/5320\/","title":{"rendered":"\u8907\u6570\u306eJavaScript\u3092\u540c\u671f\u7684\u306b\u8aad\u307f\u8fbc\u307f\u3001\u5b9f\u884c\u3059\u308b"},"content":{"rendered":"

\u901a\u5e38\u3001JavaScript\u304b\u3089script\u30bf\u30b0\u3092\u8907\u6570\u751f\u6210\u3059\u308b\u3068\u4e26\u5217\u7684\u306b\u8aad\u307f\u8fbc\u307f\u304c\u884c\u308f\u308c\u3001\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u5f8c\u306b\u751f\u6210\u3057\u305fscript\u306b\u6307\u5b9a\u3057\u305fJavaScript\u304c\u5148\u306b\u30ed\u30fc\u30c9\u3055\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u8aad\u307f\u8fbc\u3080JavaScript\u306b\u3088\u3063\u3066\u306f\u9806\u5e8f\u304c\u5fc5\u8981\uff08\u30d7\u30e9\u30b0\u30a4\u30f3\u306a\u3069\uff09\u304c\u3042\u308b\u5834\u5408\u304c\u3042\u308a\u3001script\u3092\u4f5c\u6210\u3057\u305f\u9806\u306b\u8aad\u307f\u8fbc\u3080\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n

jQuery\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u3068\u3057\u3066\u4f5c\u6210\u3059\u308b\u3068\u4fbf\u5229\u304b\u306a\u3068\u3082\u601d\u3044jQuery plugins\u306b\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u305f\u306e\u3067\u3059\u304c\u3001\u306e\u3061\u306e\u3061\u8003\u3048\u308b\u3068\u30d7\u30e9\u30b0\u30a4\u30f3\u3068\u3057\u3066\u307e\u3067\u4f7f\u3044\u305f\u3044\u3088\u3046\u306a\u51e6\u7406\u3067\u306f\u306a\u304b\u3063\u305f\u306e\u3067\u30b5\u30a4\u30c8\u306b\u500b\u5225\u30da\u30fc\u30b8\u3092\u4f5c\u6210\u305b\u305a\u306b\u516c\u958b\u7528\u306b\u4fee\u6b63\u3057\u305f\u30b3\u30fc\u30c9\u306e\u65ad\u7247\u3092\u8cbc\u308a\u3064\u3051\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n

\u3082\u3057\u3001jQuery\u30d7\u30e9\u30b0\u30a4\u30f3\u3068\u3057\u3066\u5229\u7528\u3057\u305f\u3044\u65b9\u306f\u4e0a\u8a18\u306e\u30ea\u30f3\u30af\u304b\u3089js\u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u4e0b\u8a18\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3068\u306f\u82e5\u5e72\u4f7f\u3044\u65b9\u304c\u9055\u3046\uff08\u540c\u671f\u30fb\u975e\u540c\u671f\u4e21\u65b9\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u3059\uff09\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n

\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4f5c\u6210\u3057\u305f\u30b3\u30fc\u30c9\u304c\u4ee5\u4e0b\u3067\u3059\u3002<\/p>\n

\r\nfunction load_sync_js(src_list) {\r\n        var rootScript = _create_script(src_list[0]);\r\n        var s = rootScript;\r\n        var head = document.getElementsByTagName('head')[0];\r\n        for (var i=0; i=src_list.length) break;\r\n                var nextScript = _create_script(src_list[i+1]);\r\n                s.onload = function(){\r\n                        if(s.initialized) return;\r\n                        s.initialized = true;\r\n                        head.appendChild(nextScript);\r\n                };\r\n                s.onreadystatechange = function() {\r\n                        if(s.initialized) return;\r\n                        if (s.readyState == 'complete') {\r\n                                s.initialized = true;\r\n                                head.appendChild(nextScript);\r\n                        }\r\n                };\r\n                s = nextScript;\r\n        }\r\n        head.appendChild(rootScript);\r\n}\r\nfunction _create_script(src) {\r\n        var s = document.createElement('script');\r\n        s.type = 'text\/javascript';\r\n        s.src = src;\r\n        s.initialized = false;\r\n        return s;\r\n}\r\n<\/src_list><\/pre>\n

\u30dd\u30a4\u30f3\u30c8\u306f\u3001\u6700\u521d\u306b\u8aad\u307f\u8fbc\u3080rootScript\u306eonload,onreadystatechange\u30a4\u30d9\u30f3\u30c8\u306b\u8aad\u307f\u8fbc\u307f\u304c\u884c\u308f\u308c\u3066\u3044\u306a\u3051\u308c\u3070\u6b21\u306escript\u30bf\u30b0\u3092\u4f5c\u6210\u3059\u308b\u51e6\u7406\u3092\u518d\u5e30\u7684\u306bbind\u3057\u3066\u3044\u308b\u70b9\u3067\u3059\u3002<\/p>\n

\u4f7f\u3044\u65b9\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

\r\nload_sync_js(['.\/hoge.js','.\/foo.js']);\r\n<\/pre>\n

\u3082\u3061\u308d\u3093\u3001\u5916\u90e8JavaScript\u3067\u3082\u5927\u4e08\u592b\u3067\u3059\u3002<\/p>\n

\r\nload_sync_js(['https:\/\/example.com\/example1.js','https:\/\/example.com\/example2.js']);\r\n<\/pre>\n

\u8ffd\u8a18\uff1a2011.05.05 20:21<\/strong>
\n\u4e0a\u8a18\u306b\u63b2\u8f09\u3057\u3066\u3044\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u306b\u306f\u3001\u6307\u5b9a\u3057\u305f\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u3046\u3061\u3001\u6700\u521d\u3068\u6700\u5f8c\u306e\u3082\u306e\u3057\u304b\u6b63\u5e38\u306b\u30ed\u30fc\u30c9\u3055\u308c\u306a\u3044\u3068\u3044\u3046\u30d0\u30b0\u3092\u542b\u3093\u3067\u3044\u307e\u3059\u3002jQuery\u30d7\u30e9\u30b0\u30a4\u30f3\u7248\u306b\u306a\u3063\u3066\u3057\u3042\u3044\u307e\u3059\u304c\u3001\u4e0b\u8a18\u306e\u3082\u306e\u3092\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n

JavaScript Loader jQuery Plugin | jQuery Plugins<\/p>\n","protected":false},"excerpt":{"rendered":"

\u901a\u5e38\u3001JavaScript\u304b\u3089script\u30bf\u30b0\u3092\u8907\u6570\u751f\u6210\u3059\u308b\u3068\u4e26\u5217\u7684\u306b\u8aad\u307f\u8fbc\u307f\u304c\u884c\u308f\u308c\u3001\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u5f8c\u306b\u751f\u6210\u3057\u305fscript\u306b\u6307\u5b9a\u3057\u305fJavaScript\u304c\u5148\u306b\u30ed\u30fc\u30c9\u3055\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u8aad\u307f … \u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":2,"featured_media":9223372036854775807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1980],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/5320"}],"collection":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/comments?post=5320"}],"version-history":[{"count":0,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/5320\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media\/9223372036854775807"}],"wp:attachment":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media?parent=5320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/categories?post=5320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/tags?post=5320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}