SlideShare uma empresa Scribd logo
1 de 11
Lazy Loading
“do the least work possible”
Evolution of javascript application
           optimization

 <head> <script> code </script> </head>

 Many separate script file as separate
 resources (cacheable)

 Far futures expires headers, e-tags

 Reduce requests: minification and
 concatenation

 Serve from static, “cookieless” domains, CDNs

 We’re still slow....what’s next?
The problem: the file
   keeps growing!
Not scalable for large applications

Complexity of production support increases,
more code = more liability (one syntax error
and boom!)

Big ball of mud

Hard to maintain development vs. production
systems (dev mode with separate files, build
process, versioning, etc)
The solution: lazy load
Always load core javascript framework
(jquery + your framework/bootstrap)  You don’t have a
framework???




Lazy load models and controllers based upon
interaction

Don’t have an MVC framework? coremvc,
JavascriptMVC, many others

Avoid dependency hell: keep it one-level/
controller based. Don’t “abuse” prototype
Fine Lines
              Understand
    DOMContentLoaded and load events
Absolute final “End User” experience. DOMContentLoaded = DOM is
ready, loaded. load = all page components have finished loading

It matters even for a primed cache, big/many javascript
components delay final onload event, causing loading/blocking

It takes time to parse & evaluate big javascript files. Caching can’t
fix this, users see it
Possible improvements:
 why invest the time?
Increase simplicity

“Snappiness”, reduce memory footprint --
less code in memory

Hide latency

Manage user expectations (users expect to
wait when they do some action the first
time, but hate waiting on every page load)

Evaluate your site metrics (passers-by vs.
heavy users), cache rate percentage for
Where do I start?
Today (probably yesterday)

Evaluate your application, especially your users

Y-SLOW & Firebug Net Panel. Google Page Speed Plugin

Look at existing solutions

    jquery plugins available

    yuiloader, requirejs, many others as well

    dojo loader & dep management

    (maybe) do your own - simple bootstrap with simple API

    test in all target browsers for loading indications. hacks will be
    needed
<html>
      A maybe-contrived example
<head>
<title>LazyLoading Test</title>
<script>
         var AsyncLoader = function(src, cb) {
         var s = document.createElement('script');
         s.type = 'text/javascript';
                             s.async = true;
                             s.src = src + '?=' + Math.random(); // make sure we are loading this once
                             if(typeof(cb) == 'function') {
                                       this.onLoad(cb);
                             }



                                                                                                  https://gist.github.com/904251
                             var onLoad = this.onLoad();

                                     s.onreadystatechange = function() {
                                              if(this.readyState == 'loaded' ||
                                                         this.readyState == 'complete') {
                                                         onLoad();
                                              }
                                     };
                                     s.onload = onLoad;
                                     s.onerror = onLoad;

                            var asyncLoad = function() {
                                    setTimeout(function() {
                                              document.getElementById('msg').innerHTML = document.getElementById('msg').innerHTML + 'Loading...';
                                              var x = document.getElementsByTagName('script')[0];
                                              var head = document.getElementsByTagName("head")[0];
                                              x.parentNode.insertBefore(s, x);
                                    }, 1000);
                            };

                            if (window.attachEvent) {
                                       window.attachEvent('onload', asyncLoad);
                            } else if(window.addEventListener) {
                                       window.addEventListener('load', asyncLoad, false);
                            }
         };

         AsyncLoader.prototype.onLoad = function(cb) {
                if(typeof(cb) == 'function') {
                           this._cb = cb;
                } else if(typeof(this._cb) == 'function') {
                           var that = this;
                           return function() {
                                     that._cb();
                           }
                }
         };

         var loader = new AsyncLoader('http://www.mersenneforum.org/txt/43.txt', function() {
                  document.getElementById('msg').innerHTML = document.getElementById('msg').innerHTML + 'done';
         });

</script>
</head>
<body>
<h1>Javascript Lazy Loading Test</h1>
<div id='msg'></div>
<div style="height:1000px; width: 50px; background: #aaaaaa;"></div>
</body>
</html>
Desired Outcome
Minimal loading indication across most
browsers. “Defer” load until after load or
your custom event

Good for third party javascripts which may
be slow or trigger more blocking requests
themselves which continue page loading

Die silently, but handle it. Don’t go on like
nothing happened; don’t try to use code that
didn’t load!
Example Results


http://www.letseehere.com/examples/lazy_loading/
thanks
                   Johnathan Leppert
                  Developer, Manta.com
                  twitter: @iamleppert
              johnathan.leppert@gmail.com
               Let me google that for you
                    (further reading):
https://gist.github.com/904251
http://velocityconf.com/velocity2010/public/schedule/detail/15412
http://ajaxpatterns.org/On-Demand_Javascript
http://jasonleveille.com/blog/2008/05/javascript-lazy-loading
http://developer.yahoo.com/yui/3/yui/
http://requirejs.org
http://wonko.com/post/painless_javascript_lazy_loading_with_lazyload
http://ajaxian.com/archives/a-technique-for-lazy-script-loading
http://www.digital-web.com/articles/improve_page_performance_with_lazy_loading/

Mais conteúdo relacionado

Mais procurados

The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it meansRobert Nyman
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for JoomlaLuke Summerfield
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileJavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileRobert Nyman
 
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresJavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresRobert Nyman
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)Domenic Denicola
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoJavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoRobert Nyman
 
Realm.io par Clement Sauvage
Realm.io par Clement SauvageRealm.io par Clement Sauvage
Realm.io par Clement SauvageCocoaHeads France
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresJavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresRobert Nyman
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJSSylvain Zimmer
 
JavaScript promise
JavaScript promiseJavaScript promise
JavaScript promiseeslam_me
 
Boom! Promises/A+ Was Born
Boom! Promises/A+ Was BornBoom! Promises/A+ Was Born
Boom! Promises/A+ Was BornDomenic Denicola
 
Getting Reactive with Cycle.js and xstream
Getting Reactive with Cycle.js and xstreamGetting Reactive with Cycle.js and xstream
Getting Reactive with Cycle.js and xstreamSteve Lee
 
¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?jaespinmora
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptJon Kruger
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperJon Kruger
 

Mais procurados (20)

The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileJavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
 
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresJavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoJavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
 
Realm.io par Clement Sauvage
Realm.io par Clement SauvageRealm.io par Clement Sauvage
Realm.io par Clement Sauvage
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresJavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
HTML,CSS Next
HTML,CSS NextHTML,CSS Next
HTML,CSS Next
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
 
JavaScript promise
JavaScript promiseJavaScript promise
JavaScript promise
 
Boom! Promises/A+ Was Born
Boom! Promises/A+ Was BornBoom! Promises/A+ Was Born
Boom! Promises/A+ Was Born
 
Getting Reactive with Cycle.js and xstream
Getting Reactive with Cycle.js and xstreamGetting Reactive with Cycle.js and xstream
Getting Reactive with Cycle.js and xstream
 
¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScript
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
 

Destaque

การโพสต์รูปในเว็บFlickr
การโพสต์รูปในเว็บFlickrการโพสต์รูปในเว็บFlickr
การโพสต์รูปในเว็บFlickrปวริศา
 
Art Salon @ SENI
Art Salon @ SENIArt Salon @ SENI
Art Salon @ SENIKC Y
 
Jenny Ekmark En förstudie hur Skogrand skyltdesign kan positionera sig på nätet
Jenny Ekmark En förstudie hur Skogrand skyltdesign kan positionera sig på nätetJenny Ekmark En förstudie hur Skogrand skyltdesign kan positionera sig på nätet
Jenny Ekmark En förstudie hur Skogrand skyltdesign kan positionera sig på nätetKommunikation Nya Medier 08-10
 
Seo by jamal
Seo by jamalSeo by jamal
Seo by jamalMagsnet
 
Ministry Presentation
Ministry PresentationMinistry Presentation
Ministry PresentationJApaxton
 
¿Qué es la ley de la oferta y la demanda
¿Qué es la ley de la oferta y la demanda¿Qué es la ley de la oferta y la demanda
¿Qué es la ley de la oferta y la demandaconchatumare
 
Mp ru 2012
Mp ru 2012Mp ru 2012
Mp ru 2012sherif
 
мп стратегия достижения вашего успеха
мп стратегия достижения вашего успехамп стратегия достижения вашего успеха
мп стратегия достижения вашего успехаsherif
 
เทคโนโลยี Web 2
เทคโนโลยี Web 2เทคโนโลยี Web 2
เทคโนโลยี Web 2ปวริศา
 
Fpt Tesi Scavenging Definitiva
Fpt Tesi Scavenging DefinitivaFpt Tesi Scavenging Definitiva
Fpt Tesi Scavenging DefinitivaEnzo Ceroni
 
บทเรียน เรื่อง คำกริยา ป.5
บทเรียน เรื่อง คำกริยา ป.5บทเรียน เรื่อง คำกริยา ป.5
บทเรียน เรื่อง คำกริยา ป.5ปวริศา
 

Destaque (19)

UX Psychology 1st Track.
UX Psychology 1st Track.UX Psychology 1st Track.
UX Psychology 1st Track.
 
I18n
I18nI18n
I18n
 
การโพสต์รูปในเว็บFlickr
การโพสต์รูปในเว็บFlickrการโพสต์รูปในเว็บFlickr
การโพสต์รูปในเว็บFlickr
 
Art Salon @ SENI
Art Salon @ SENIArt Salon @ SENI
Art Salon @ SENI
 
EQUUSTUR
EQUUSTUR EQUUSTUR
EQUUSTUR
 
Jenny Ekmark En förstudie hur Skogrand skyltdesign kan positionera sig på nätet
Jenny Ekmark En förstudie hur Skogrand skyltdesign kan positionera sig på nätetJenny Ekmark En förstudie hur Skogrand skyltdesign kan positionera sig på nätet
Jenny Ekmark En förstudie hur Skogrand skyltdesign kan positionera sig på nätet
 
DE VINS
DE VINSDE VINS
DE VINS
 
Bilaga 1 3 Adhdkvinnor
Bilaga 1 3 AdhdkvinnorBilaga 1 3 Adhdkvinnor
Bilaga 1 3 Adhdkvinnor
 
SALTRA BANDA
SALTRA BANDASALTRA BANDA
SALTRA BANDA
 
Lea PåLsson Knm08 Slutprojekt adhdkvinnor.se
Lea PåLsson Knm08 Slutprojekt adhdkvinnor.seLea PåLsson Knm08 Slutprojekt adhdkvinnor.se
Lea PåLsson Knm08 Slutprojekt adhdkvinnor.se
 
Seo by jamal
Seo by jamalSeo by jamal
Seo by jamal
 
Ministry Presentation
Ministry PresentationMinistry Presentation
Ministry Presentation
 
UX Psychology 2nd Track.
UX Psychology 2nd Track.UX Psychology 2nd Track.
UX Psychology 2nd Track.
 
¿Qué es la ley de la oferta y la demanda
¿Qué es la ley de la oferta y la demanda¿Qué es la ley de la oferta y la demanda
¿Qué es la ley de la oferta y la demanda
 
Mp ru 2012
Mp ru 2012Mp ru 2012
Mp ru 2012
 
мп стратегия достижения вашего успеха
мп стратегия достижения вашего успехамп стратегия достижения вашего успеха
мп стратегия достижения вашего успеха
 
เทคโนโลยี Web 2
เทคโนโลยี Web 2เทคโนโลยี Web 2
เทคโนโลยี Web 2
 
Fpt Tesi Scavenging Definitiva
Fpt Tesi Scavenging DefinitivaFpt Tesi Scavenging Definitiva
Fpt Tesi Scavenging Definitiva
 
บทเรียน เรื่อง คำกริยา ป.5
บทเรียน เรื่อง คำกริยา ป.5บทเรียน เรื่อง คำกริยา ป.5
บทเรียน เรื่อง คำกริยา ป.5
 

Semelhante a Lazy Loading Because I'm Lazy

Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScriptAndrew Dupont
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bitsChris Saylor
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
Reliable Javascript
Reliable Javascript Reliable Javascript
Reliable Javascript Glenn Stovall
 
Designing a JavaFX Mobile application
Designing a JavaFX Mobile applicationDesigning a JavaFX Mobile application
Designing a JavaFX Mobile applicationFabrizio Giudici
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkIndicThreads
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Frameworkvhazrati
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfacesmaccman
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptjnewmanux
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsFrancois Zaninotto
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the mastersAra Pehlivanian
 
HTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranHTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranRobert Nyman
 
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...GITS Indonesia
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript MisunderstoodBhavya Siddappa
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web ModuleMorgan Cheng
 

Semelhante a Lazy Loading Because I'm Lazy (20)

Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Reliable Javascript
Reliable Javascript Reliable Javascript
Reliable Javascript
 
Designing a JavaFX Mobile application
Designing a JavaFX Mobile applicationDesigning a JavaFX Mobile application
Designing a JavaFX Mobile application
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfaces
 
Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
Java script for web developer
Java script for web developerJava script for web developer
Java script for web developer
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the masters
 
HTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranHTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - Altran
 
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
 
Alert
AlertAlert
Alert
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
 
NodeJS
NodeJSNodeJS
NodeJS
 

Último

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Último (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

Lazy Loading Because I'm Lazy

  • 1. Lazy Loading “do the least work possible”
  • 2. Evolution of javascript application optimization <head> <script> code </script> </head> Many separate script file as separate resources (cacheable) Far futures expires headers, e-tags Reduce requests: minification and concatenation Serve from static, “cookieless” domains, CDNs We’re still slow....what’s next?
  • 3. The problem: the file keeps growing! Not scalable for large applications Complexity of production support increases, more code = more liability (one syntax error and boom!) Big ball of mud Hard to maintain development vs. production systems (dev mode with separate files, build process, versioning, etc)
  • 4. The solution: lazy load Always load core javascript framework (jquery + your framework/bootstrap) You don’t have a framework??? Lazy load models and controllers based upon interaction Don’t have an MVC framework? coremvc, JavascriptMVC, many others Avoid dependency hell: keep it one-level/ controller based. Don’t “abuse” prototype
  • 5. Fine Lines Understand DOMContentLoaded and load events Absolute final “End User” experience. DOMContentLoaded = DOM is ready, loaded. load = all page components have finished loading It matters even for a primed cache, big/many javascript components delay final onload event, causing loading/blocking It takes time to parse & evaluate big javascript files. Caching can’t fix this, users see it
  • 6. Possible improvements: why invest the time? Increase simplicity “Snappiness”, reduce memory footprint -- less code in memory Hide latency Manage user expectations (users expect to wait when they do some action the first time, but hate waiting on every page load) Evaluate your site metrics (passers-by vs. heavy users), cache rate percentage for
  • 7. Where do I start? Today (probably yesterday) Evaluate your application, especially your users Y-SLOW & Firebug Net Panel. Google Page Speed Plugin Look at existing solutions jquery plugins available yuiloader, requirejs, many others as well dojo loader & dep management (maybe) do your own - simple bootstrap with simple API test in all target browsers for loading indications. hacks will be needed
  • 8. <html> A maybe-contrived example <head> <title>LazyLoading Test</title> <script> var AsyncLoader = function(src, cb) { var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = src + '?=' + Math.random(); // make sure we are loading this once if(typeof(cb) == 'function') { this.onLoad(cb); } https://gist.github.com/904251 var onLoad = this.onLoad(); s.onreadystatechange = function() { if(this.readyState == 'loaded' || this.readyState == 'complete') { onLoad(); } }; s.onload = onLoad; s.onerror = onLoad; var asyncLoad = function() { setTimeout(function() { document.getElementById('msg').innerHTML = document.getElementById('msg').innerHTML + 'Loading...'; var x = document.getElementsByTagName('script')[0]; var head = document.getElementsByTagName("head")[0]; x.parentNode.insertBefore(s, x); }, 1000); }; if (window.attachEvent) { window.attachEvent('onload', asyncLoad); } else if(window.addEventListener) { window.addEventListener('load', asyncLoad, false); } }; AsyncLoader.prototype.onLoad = function(cb) { if(typeof(cb) == 'function') { this._cb = cb; } else if(typeof(this._cb) == 'function') { var that = this; return function() { that._cb(); } } }; var loader = new AsyncLoader('http://www.mersenneforum.org/txt/43.txt', function() { document.getElementById('msg').innerHTML = document.getElementById('msg').innerHTML + 'done'; }); </script> </head> <body> <h1>Javascript Lazy Loading Test</h1> <div id='msg'></div> <div style="height:1000px; width: 50px; background: #aaaaaa;"></div> </body> </html>
  • 9. Desired Outcome Minimal loading indication across most browsers. “Defer” load until after load or your custom event Good for third party javascripts which may be slow or trigger more blocking requests themselves which continue page loading Die silently, but handle it. Don’t go on like nothing happened; don’t try to use code that didn’t load!
  • 11. thanks Johnathan Leppert Developer, Manta.com twitter: @iamleppert johnathan.leppert@gmail.com Let me google that for you (further reading): https://gist.github.com/904251 http://velocityconf.com/velocity2010/public/schedule/detail/15412 http://ajaxpatterns.org/On-Demand_Javascript http://jasonleveille.com/blog/2008/05/javascript-lazy-loading http://developer.yahoo.com/yui/3/yui/ http://requirejs.org http://wonko.com/post/painless_javascript_lazy_loading_with_lazyload http://ajaxian.com/archives/a-technique-for-lazy-script-loading http://www.digital-web.com/articles/improve_page_performance_with_lazy_loading/

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n