Async JS loading
   Kornel Lesiński
          <London JS 11.2011>
defer
        async
                DOM
            script loaders
MERGE
MINIFY
 GZIP
voluptate  velit  esse  cillum  dolore  eu  
fugiat  nulla  pariatur.  Excepteur  sint  
occaecat  cupidatat  non  proident,  sunt  in  
culpa  qui  officia  deserunt  mollit  anim  id  
est  laborum.
                </data>
            </section>
        </article>
        <script  src=all-­‐minified.js></script>
    </body>
</html>
document.write()
    onload
DOMContentReady
<script  defer>
<script  defer  src=//example.com/spam-­‐library.js>
<script  defer  src=/js/add-­‐spam-­‐button.js>

Lorem  ipsum  dolor  sit  amet,  consectetur  
adipisicing  elit,  sed  do  eiusmod  tempor  
incididunt  ut  labore  et  dolore  magna  aliqua.

<script  src=//example.com/spam-­‐library.js>
<script  src=/js/add-­‐spam-­‐button.js>

</body>
“The exact processing
     details for these
attributes are, for mostly
    historical reasons,
 somewhat non-trivial”
<script  async>
<script  async  src=//example.com/spam-­‐library.js>

Lorem  ipsum  dolor  sit  amet,  consectetur  
adipisicing  elit,  sed  do  eiusmod  tempor  
incididunt  ut  labore  et  dolore  magna  aliqua.




</body>
NOBODY
 EXPECTS
  ASYNC
EXECUTION
<script  async  src=//example.com/spam-­‐library.js>
<script  async  src=//example.com/spam-­‐library.js>

Lorem  ipsum  dolor  sit  amet,  consectetur  
adipisicing  elit,  sed  <script  async  src=//
example.com/spam-­‐library.js>  do  eiusmod  tempor  
incididunt  ut  labore  et  dolore  magna  aliqua.

<script  async  src=//example.com/spam-­‐library.js>  
</body>
<script  async  src=//example.com/spam-­‐library.js>
<script  async  src=//example.com/spam-­‐library.js>
<script  async  src=/js/add-­‐spam-­‐button.js>
<script  async  src=library+add-­‐spam-­‐button.js>
<script  async  src=//example.com/spam-­‐library.js  
    onload="one=true;  if  (one  &&  two)  do_spam()">
                                   
<script  async  src=/js/add-­‐spam-­‐button.js
    onload="two=true;  if  (one  &&  two)  do_spam()">
<script  async  src=//example.com/spam-­‐library.js  
    onload="one=true;  if  (one  &&  two)  do_spam()">
                                   
<script  async  src=/js/add-­‐spam-­‐button.js
    onload="two=true;  if  (one  &&  two)  do_spam()">
DOM
doc.createElement('script')
script.async  =  true
script.src  =  "ga.js"
<script>
ga  =  doc.createElement('script')  
ga.async  =  true
ga.src  =  'ga.js'
s  =  doc.getElementsByTagName('script')[0]
s.parentNode.insertBefore(ga,  s)
</script>
Script loaders
<nosrsly>
Progressive enhancement
<html  class="no-­‐js">
  <head>
  <script>
    document.documentElement.className      loading'
                                        ='
  </script>
  <style>
  .no-­‐js  .widget  {overflow:scroll}
  .loading  .widget  {visibility:hidden}
  </style>
defer
MERGE
                     ?
MINIFY   async   ?


 GZIP    DOM     ?
                     ?
pornel.net /asyncjs
   @pornelski

More Related Content

PDF
ServiceWorker: New game changer is coming!
PDF
PDF
Node intro
PDF
Packing it all: JavaScript module bundling from 2000 to now
PDF
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
PPTX
Getting started with node.js
PPTX
Javascript first-class citizenery
PPTX
ServiceWorker: New game changer is coming!
Node intro
Packing it all: JavaScript module bundling from 2000 to now
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
Getting started with node.js
Javascript first-class citizenery

What's hot (20)

PPTX
intro to Angular js
KEY
Requirejs
PDF
Build web application by express
PDF
Service worker API
PDF
AngularJS Deep Dives (NYC GDG Apr 2013)
PDF
Svelte JS introduction
PPTX
Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...
PDF
XSS Defeating Trick ~=ABK=~ WhitePaper
PDF
Event Driven Architecture Concepts in Web Technologies - Part 1
PPTX
Testing frontends with nightwatch & saucelabs
PDF
Web Workers
PDF
React.js in real world apps.
PPTX
Packing for the Web with Webpack
PPTX
Introduction to java_script
PDF
Grunt.js and Yeoman, Continous Integration
PDF
Introduction to REST API with Node.js
PDF
Getting started with node JS
PDF
Javascript #2.2 : jQuery
PDF
Node.js first slide
PDF
Web Design Workshop Part 2
intro to Angular js
Requirejs
Build web application by express
Service worker API
AngularJS Deep Dives (NYC GDG Apr 2013)
Svelte JS introduction
Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...
XSS Defeating Trick ~=ABK=~ WhitePaper
Event Driven Architecture Concepts in Web Technologies - Part 1
Testing frontends with nightwatch & saucelabs
Web Workers
React.js in real world apps.
Packing for the Web with Webpack
Introduction to java_script
Grunt.js and Yeoman, Continous Integration
Introduction to REST API with Node.js
Getting started with node JS
Javascript #2.2 : jQuery
Node.js first slide
Web Design Workshop Part 2
Ad

Viewers also liked (10)

PDF
Front matter
PDF
Presentazione PB Group
PPT
PPSX
Supply chain-Mohamed Attia-MBA
PDF
The girls
PDF
Quantum UI & Workflow for Essex
PPS
Corazon
PPSX
Happy Mother’S Day
PPTX
Moments in Life (with help from Jane Seabrook
PPT
Brazil
Front matter
Presentazione PB Group
Supply chain-Mohamed Attia-MBA
The girls
Quantum UI & Workflow for Essex
Corazon
Happy Mother’S Day
Moments in Life (with help from Jane Seabrook
Brazil
Ad

Recently uploaded (20)

PDF
sbt 2.0: go big (Scala Days 2025 edition)
PDF
Statistics on Ai - sourced from AIPRM.pdf
PDF
Co-training pseudo-labeling for text classification with support vector machi...
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PDF
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PPTX
future_of_ai_comprehensive_20250822032121.pptx
PDF
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
PDF
SaaS reusability assessment using machine learning techniques
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
Aug23rd - Mulesoft Community Workshop - Hyd, India.pdf
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
sbt 2.0: go big (Scala Days 2025 edition)
Statistics on Ai - sourced from AIPRM.pdf
Co-training pseudo-labeling for text classification with support vector machi...
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
Early detection and classification of bone marrow changes in lumbar vertebrae...
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
Convolutional neural network based encoder-decoder for efficient real-time ob...
future_of_ai_comprehensive_20250822032121.pptx
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
SaaS reusability assessment using machine learning techniques
Custom Battery Pack Design Considerations for Performance and Safety
Aug23rd - Mulesoft Community Workshop - Hyd, India.pdf
Enhancing plagiarism detection using data pre-processing and machine learning...
Comparative analysis of machine learning models for fake news detection in so...
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...

Asynchronous JavaScript loading