際際滷

際際滷Share a Scribd company logo
JavaScript Dynamic Loading
JavaScript Dynamic Loading
Response Time
0

                0.1


                 1


Jakob Nielsen   10
0

                0.1


                 1


Jakob Nielsen   10
JavaScript Dynamic Loading
Huge JavaScript
91%
JavaScript Dynamic Loading
75%
JavaScript Dynamic Loading
Heavy loading   Quick response
JavaScript Dynamic Loading
JavaScript
JavaScript Dynamic Loading
JavaScript Dynamic Loading
JavaScript Dynamic Loading
<html>
 <body>
    :
  <script src=/slideshow/javascript-dynamic-loading/7693028/ ̄jQuery.js ̄></script>
  <script src= ̄jq-plugin-x.js ̄></script>
  <script src= ̄jq-plugin-y.js ̄></script>
  <script src= ̄prototype.js ̄></script>
  <script src= ̄pt-plugin-x.js ̄></script>
  <script src= ̄pt-plugin-y.js ̄></script>
  <script src= ̄init-rendering.js ̄>
  <script src= ̄facebook-plugin.js ̄>
  <script src= ̄twitter-plugin.js ̄>
 </body>
</html>
<html>
 <head>
  <script src=/slideshow/javascript-dynamic-loading/7693028/ ̄loader.js ̄></script>
  <script>
     document.onload = function() {
       /* do loading */
     };
  </script>
 </head>
</html>
How
XHR + eval

var xhrObj = new XMLHttpRequest();
xhrObj.onreadystatechange =
 function() {
   if ( xhrObj.readyState == 4 ) {
     eval(xhrObj.responseText);
   }
 };
xhrObj.open('GET', 'A.js', true);
xhrObj.send('');
XHR + injection
var xhrObj = new XMLHttpRequest();
xhrObj.onreadystatechange =
 function() {
   if ( xhrObj.readyState == 4 ) {
     var scriptElem = document.createElement('script');
     var headElem = document.getElementsByTagName('head')[0];
     headElem.appendChild(scriptElem);
     scriptElem.text = xhrObj.responseText;
   }
 };
xhrObj.open('GET', 'A.js', true);
xhrObj.send('');
dom element


var scriptElem = document.createElement('script');
scriptElem.type= 'text/javascript';
scriptElem.src = /slideshow/javascript-dynamic-loading/7693028/&

var headElem = document.getElementsByTagName('head')[0];
headElem.appendChild(scriptElem);
dom element (not execute)


var scriptElem = document.createElement('script');
scriptElem.type= 'text/html';
scriptElem.src = /slideshow/javascript-dynamic-loading/7693028/&

var headElem = document.getElementsByTagName('head')[0];
headElem.appendChild(scriptElem);
JavaScript Dynamic Loading
JavaScript Dynamic Loading
XHR
var xhrObj = new XMLHttpRequest();

xhrObj.onreadystatechange =
 function() {
   if ( xhrObj.readyState == 4 ) {
     /* eval or injection */

        /* JavaScript onload */
    }
  };

xhrObj.open('GET', 'A.js', true);
xhrObj.send('');
dom element


var scriptElem = document.createElement('script');
scriptElem.src = /slideshow/javascript-dynamic-loading/7693028/&

scriptElem.onload = function() { /* JavaScript onload */ };

document.getElementsByTagName('head').appendChild(scriptElem);
with IE :)
var scriptElem = document.createElement('script');
scriptElem.src = /slideshow/javascript-dynamic-loading/7693028/&

scriptElem.onload = function() {
  if ( !scriptElem.onloadDone ) {
    scriptElem.onloadDone = true;
    /* JavaScript onload */
  }
};
scriptElem.onreadystatechange = function() { /* for IE */
  if ( xhrObj.readyState == 4 || xhrObj.readyState == 2 ) {
    if ( !scriptElem.onloadDone ) {
      scriptElem.onloadDone = true;
      /* JavaScript onload */
    }
  }
};

document.getElementsByTagName('head').appendChild(scriptElem);
JavaScript Dynamic Loading
When / What
JavaScript Dynamic Loading
JavaScript Dynamic Loading
JavaScript Dynamic Loading
JavaScript Dynamic Loading
The three things you should know
1
JavaScript Dynamic Loading
2
JavaScript Dynamic Loading
3
JavaScript Dynamic Loading
UI
Points
JavaScript Dynamic Loading
One more thing ...
JavaScript Dynamic Loading
JavaScript Dynamic Loading
JavaScript Dynamic Loading
Thunk you
JavaScript Dynamic Loading
JavaScript Dynamic Loading

More Related Content

What's hot (20)

Testov│n┴ prakticky
Testov│n┴ praktickyTestov│n┴ prakticky
Testov│n┴ prakticky
Filip Proch│zka
?
aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.
bhavesh lande
?
8. CodeIgniter move2
8. CodeIgniter move28. CodeIgniter move2
8. CodeIgniter move2
Razvan Raducanu, PhD
?
Acessardados Aula7
Acessardados Aula7Acessardados Aula7
Acessardados Aula7
softeam
?
Node.js をさりげなく函り秘れた 恷除のフロントエンド並秤について
Node.js をさりげなく函り秘れた 恷除のフロントエンド並秤についてNode.js をさりげなく函り秘れた 恷除のフロントエンド並秤について
Node.js をさりげなく函り秘れた 恷除のフロントエンド並秤について
kamiyam .
?
JavaScript Assi?ncrono
JavaScript Assi?ncronoJavaScript Assi?ncrono
JavaScript Assi?ncrono
Nat? Barbosa
?
Collection pipeline par Mathieu Godart
Collection pipeline par  Mathieu GodartCollection pipeline par  Mathieu Godart
Collection pipeline par Mathieu Godart
CocoaHeads France
?
Clase 10 electiva profesional 3 aws rds php y mysql
Clase 10 electiva profesional 3 aws rds php y mysqlClase 10 electiva profesional 3 aws rds php y mysql
Clase 10 electiva profesional 3 aws rds php y mysql
Richard Eliseo Mendoza Gafaro
?
HTTP Interceptors com AngularJS
HTTP Interceptors com AngularJSHTTP Interceptors com AngularJS
HTTP Interceptors com AngularJS
Rodrigo Branas
?
React - podsumowanie z placu boju
React - podsumowanie z placu bojuReact - podsumowanie z placu boju
React - podsumowanie z placu boju
Rados?aw Mejer
?
Local storages
Local storagesLocal storages
Local storages
Дмитрий Скинтиян
?
CakePHP 並箭B初 @ogaoga
CakePHP 並箭B初 @ogaogaCakePHP 並箭B初 @ogaoga
CakePHP 並箭B初 @ogaoga
Tsutomu Ogasawara
?
Introduction to Service Worker
Introduction to Service WorkerIntroduction to Service Worker
Introduction to Service Worker
Shogo Sensui
?
Aplicacion turbogenerador java
Aplicacion turbogenerador javaAplicacion turbogenerador java
Aplicacion turbogenerador java
Jos└ Antonio Sandoval Acosta
?
Working With Ajax Frameworks
Working With Ajax FrameworksWorking With Ajax Frameworks
Working With Ajax Frameworks
Jonathan Snook
?
Memanggil prosedur sendiri dari program utama 1
Memanggil prosedur sendiri dari program utama 1Memanggil prosedur sendiri dari program utama 1
Memanggil prosedur sendiri dari program utama 1
Wildan Live
?
aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.
bhavesh lande
?
Acessardados Aula7
Acessardados Aula7Acessardados Aula7
Acessardados Aula7
softeam
?
Node.js をさりげなく函り秘れた 恷除のフロントエンド並秤について
Node.js をさりげなく函り秘れた 恷除のフロントエンド並秤についてNode.js をさりげなく函り秘れた 恷除のフロントエンド並秤について
Node.js をさりげなく函り秘れた 恷除のフロントエンド並秤について
kamiyam .
?
JavaScript Assi?ncrono
JavaScript Assi?ncronoJavaScript Assi?ncrono
JavaScript Assi?ncrono
Nat? Barbosa
?
Collection pipeline par Mathieu Godart
Collection pipeline par  Mathieu GodartCollection pipeline par  Mathieu Godart
Collection pipeline par Mathieu Godart
CocoaHeads France
?
HTTP Interceptors com AngularJS
HTTP Interceptors com AngularJSHTTP Interceptors com AngularJS
HTTP Interceptors com AngularJS
Rodrigo Branas
?
React - podsumowanie z placu boju
React - podsumowanie z placu bojuReact - podsumowanie z placu boju
React - podsumowanie z placu boju
Rados?aw Mejer
?
Introduction to Service Worker
Introduction to Service WorkerIntroduction to Service Worker
Introduction to Service Worker
Shogo Sensui
?
Working With Ajax Frameworks
Working With Ajax FrameworksWorking With Ajax Frameworks
Working With Ajax Frameworks
Jonathan Snook
?
Memanggil prosedur sendiri dari program utama 1
Memanggil prosedur sendiri dari program utama 1Memanggil prosedur sendiri dari program utama 1
Memanggil prosedur sendiri dari program utama 1
Wildan Live
?

More from Tomokazu Kiyohara (15)

JavaScript で OS X を徭啣掀
JavaScript で OS X を徭啣掀JavaScript で OS X を徭啣掀
JavaScript で OS X を徭啣掀
Tomokazu Kiyohara
?
Google Cloud Platform を屶える室g ´のごく匯何
Google Cloud Platform を屶える室g ´のごく匯何Google Cloud Platform を屶える室g ´のごく匯何
Google Cloud Platform を屶える室g ´のごく匯何
Tomokazu Kiyohara
?
イベント@Aのコツイベント@Aのコツ
イベント@Aのコツ
Tomokazu Kiyohara
?
Web API をデバックするときに駅勣なたったひとつのこと
Web API をデバックするときに駅勣なたったひとつのことWeb API をデバックするときに駅勣なたったひとつのこと
Web API をデバックするときに駅勣なたったひとつのこと
Tomokazu Kiyohara
?
苧晩から聞えるコ`ディングツ`ル
苧晩から聞えるコ`ディングツ`ル苧晩から聞えるコ`ディングツ`ル
苧晩から聞えるコ`ディングツ`ル
Tomokazu Kiyohara
?
Atom.io Quick Scripting
Atom.io Quick ScriptingAtom.io Quick Scripting
Atom.io Quick Scripting
Tomokazu Kiyohara
?
Text-Objects - vim's elegant function
Text-Objects - vim's elegant functionText-Objects - vim's elegant function
Text-Objects - vim's elegant function
Tomokazu Kiyohara
?
LiveStyle for Vim - Quick start
LiveStyle for Vim - Quick startLiveStyle for Vim - Quick start
LiveStyle for Vim - Quick start
Tomokazu Kiyohara
?
こわくないプルリク
こわくないプルリクこわくないプルリク
こわくないプルリク
Tomokazu Kiyohara
?
Github's HUB
Github's HUBGithub's HUB
Github's HUB
Tomokazu Kiyohara
?
サイバ`好張▲薊`トシステム ^DAEDALUS ̄┘瀬ぅ瀬蹈坑のB初
サイバ`好張▲薊`トシステム ^DAEDALUS ̄┘瀬ぅ瀬蹈坑のB初サイバ`好張▲薊`トシステム ^DAEDALUS ̄┘瀬ぅ瀬蹈坑のB初
サイバ`好張▲薊`トシステム ^DAEDALUS ̄┘瀬ぅ瀬蹈坑のB初
Tomokazu Kiyohara
?
Beginner's Sinatra
Beginner's SinatraBeginner's Sinatra
Beginner's Sinatra
Tomokazu Kiyohara
?
Compact Web - Remind "web compression" -
Compact Web - Remind "web compression" -Compact Web - Remind "web compression" -
Compact Web - Remind "web compression" -
Tomokazu Kiyohara
?
Zen coding15min
Zen coding15minZen coding15min
Zen coding15min
Tomokazu Kiyohara
?
雨皆意檎掘粥珂の篇楕を貧げよう
雨皆意檎掘粥珂の篇楕を貧げよう雨皆意檎掘粥珂の篇楕を貧げよう
雨皆意檎掘粥珂の篇楕を貧げよう
Tomokazu Kiyohara
?
JavaScript で OS X を徭啣掀
JavaScript で OS X を徭啣掀JavaScript で OS X を徭啣掀
JavaScript で OS X を徭啣掀
Tomokazu Kiyohara
?
Google Cloud Platform を屶える室g ´のごく匯何
Google Cloud Platform を屶える室g ´のごく匯何Google Cloud Platform を屶える室g ´のごく匯何
Google Cloud Platform を屶える室g ´のごく匯何
Tomokazu Kiyohara
?
イベント@Aのコツイベント@Aのコツ
イベント@Aのコツ
Tomokazu Kiyohara
?
Web API をデバックするときに駅勣なたったひとつのこと
Web API をデバックするときに駅勣なたったひとつのことWeb API をデバックするときに駅勣なたったひとつのこと
Web API をデバックするときに駅勣なたったひとつのこと
Tomokazu Kiyohara
?
苧晩から聞えるコ`ディングツ`ル
苧晩から聞えるコ`ディングツ`ル苧晩から聞えるコ`ディングツ`ル
苧晩から聞えるコ`ディングツ`ル
Tomokazu Kiyohara
?
Text-Objects - vim's elegant function
Text-Objects - vim's elegant functionText-Objects - vim's elegant function
Text-Objects - vim's elegant function
Tomokazu Kiyohara
?
LiveStyle for Vim - Quick start
LiveStyle for Vim - Quick startLiveStyle for Vim - Quick start
LiveStyle for Vim - Quick start
Tomokazu Kiyohara
?
サイバ`好張▲薊`トシステム ^DAEDALUS ̄┘瀬ぅ瀬蹈坑のB初
サイバ`好張▲薊`トシステム ^DAEDALUS ̄┘瀬ぅ瀬蹈坑のB初サイバ`好張▲薊`トシステム ^DAEDALUS ̄┘瀬ぅ瀬蹈坑のB初
サイバ`好張▲薊`トシステム ^DAEDALUS ̄┘瀬ぅ瀬蹈坑のB初
Tomokazu Kiyohara
?
Compact Web - Remind "web compression" -
Compact Web - Remind "web compression" -Compact Web - Remind "web compression" -
Compact Web - Remind "web compression" -
Tomokazu Kiyohara
?
雨皆意檎掘粥珂の篇楕を貧げよう
雨皆意檎掘粥珂の篇楕を貧げよう雨皆意檎掘粥珂の篇楕を貧げよう
雨皆意檎掘粥珂の篇楕を貧げよう
Tomokazu Kiyohara
?

JavaScript Dynamic Loading

  • 4. 0 0.1 1 Jakob Nielsen 10
  • 5. 0 0.1 1 Jakob Nielsen 10
  • 8. 91%
  • 10. 75%
  • 12. Heavy loading Quick response
  • 18. <html> <body> : <script src=/slideshow/javascript-dynamic-loading/7693028/ ̄jQuery.js ̄></script> <script src= ̄jq-plugin-x.js ̄></script> <script src= ̄jq-plugin-y.js ̄></script> <script src= ̄prototype.js ̄></script> <script src= ̄pt-plugin-x.js ̄></script> <script src= ̄pt-plugin-y.js ̄></script> <script src= ̄init-rendering.js ̄> <script src= ̄facebook-plugin.js ̄> <script src= ̄twitter-plugin.js ̄> </body> </html>
  • 19. <html> <head> <script src=/slideshow/javascript-dynamic-loading/7693028/ ̄loader.js ̄></script> <script> document.onload = function() { /* do loading */ }; </script> </head> </html>
  • 20. How
  • 21. XHR + eval var xhrObj = new XMLHttpRequest(); xhrObj.onreadystatechange = function() { if ( xhrObj.readyState == 4 ) { eval(xhrObj.responseText); } }; xhrObj.open('GET', 'A.js', true); xhrObj.send('');
  • 22. XHR + injection var xhrObj = new XMLHttpRequest(); xhrObj.onreadystatechange = function() { if ( xhrObj.readyState == 4 ) { var scriptElem = document.createElement('script'); var headElem = document.getElementsByTagName('head')[0]; headElem.appendChild(scriptElem); scriptElem.text = xhrObj.responseText; } }; xhrObj.open('GET', 'A.js', true); xhrObj.send('');
  • 23. dom element var scriptElem = document.createElement('script'); scriptElem.type= 'text/javascript'; scriptElem.src = /slideshow/javascript-dynamic-loading/7693028/& var headElem = document.getElementsByTagName('head')[0]; headElem.appendChild(scriptElem);
  • 24. dom element (not execute) var scriptElem = document.createElement('script'); scriptElem.type= 'text/html'; scriptElem.src = /slideshow/javascript-dynamic-loading/7693028/& var headElem = document.getElementsByTagName('head')[0]; headElem.appendChild(scriptElem);
  • 27. XHR var xhrObj = new XMLHttpRequest(); xhrObj.onreadystatechange = function() { if ( xhrObj.readyState == 4 ) { /* eval or injection */ /* JavaScript onload */ } }; xhrObj.open('GET', 'A.js', true); xhrObj.send('');
  • 28. dom element var scriptElem = document.createElement('script'); scriptElem.src = /slideshow/javascript-dynamic-loading/7693028/& scriptElem.onload = function() { /* JavaScript onload */ }; document.getElementsByTagName('head').appendChild(scriptElem);
  • 29. with IE :) var scriptElem = document.createElement('script'); scriptElem.src = /slideshow/javascript-dynamic-loading/7693028/& scriptElem.onload = function() { if ( !scriptElem.onloadDone ) { scriptElem.onloadDone = true; /* JavaScript onload */ } }; scriptElem.onreadystatechange = function() { /* for IE */ if ( xhrObj.readyState == 4 || xhrObj.readyState == 2 ) { if ( !scriptElem.onloadDone ) { scriptElem.onloadDone = true; /* JavaScript onload */ } } }; document.getElementsByTagName('head').appendChild(scriptElem);
  • 36. The three things you should know
  • 37. 1
  • 39. 2
  • 41. 3
  • 43. UI

Editor's Notes