JS Loading strategies
-
Upload
caridy-patino -
Category
Documents
-
view
2.693 -
download
0
description
Transcript of JS Loading strategies
![Page 1: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/1.jpg)
YUI 3 Loading Strategies
Caridy Patino / @caridyFrontend EngineerYahoo! SearchYUI Evangelist
![Page 2: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/2.jpg)
Evolution
![Page 3: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/3.jpg)
![Page 4: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/4.jpg)
![Page 5: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/5.jpg)
developer.yahoo.com/performance/rules.html
![Page 6: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/6.jpg)
Put Scripts at Bottom
![Page 7: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/7.jpg)
Minimize HTTP Requests
![Page 8: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/8.jpg)
Use a Content Delivery Network (CDN)
![Page 9: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/9.jpg)
![Page 10: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/10.jpg)
JS Loader Frameworks changed the game
![Page 11: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/11.jpg)
YUI LABjs HeadJS ControlJS
RequireJS Load.jsYepNope.js $script.js
LazyLoad curl.js DeferJS jquery.defer.js jQl
DominateJS JSLBootstrap StealJS
bdLoad NBL.jshttps://spreadsheets.google.com/ccc?key=0Aqln2akPWiMIdERkY3J2OXdOUVJDTkNSQ2ZsV3hoWVE#gid=0
![Page 12: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/12.jpg)
![Page 13: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/13.jpg)
dd, substitute and slider
tabview, oop, event, node, widget, etc
yui seed
loader
![Page 14: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/14.jpg)
Static Combo Strategy
![Page 15: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/15.jpg)
![Page 16: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/16.jpg)
![Page 17: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/17.jpg)
Data-driven initialization routine
![Page 18: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/18.jpg)
Using app-rollout files
![Page 19: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/19.jpg)
Using app-rollout files
![Page 20: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/20.jpg)
Rollout vs Loader
![Page 21: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/21.jpg)
Rollout Composition
Library
Plugins
CustomInit.js
![Page 22: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/22.jpg)
A big app-rollout takes more time to download and can potentially freeze the browser
![Page 23: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/23.jpg)
Simple rollout
![Page 24: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/24.jpg)
Interactivity Core & Lazy Components
![Page 25: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/25.jpg)
![Page 26: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/26.jpg)
Defining the interactivity core is
crucial
![Page 27: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/27.jpg)
![Page 28: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/28.jpg)
Core and Lazy Components
core rollout
lazy components
![Page 29: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/29.jpg)
Parallel Download Strategy
![Page 30: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/30.jpg)
Get app-rollout early without compromising domready and onload
![Page 31: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/31.jpg)
“Ideal Solution”
![Page 32: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/32.jpg)
![Page 33: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/33.jpg)
Parallel Download: Challenges
• Produce a VERY tiny non-blocking bootstrap
• Avoid blocking onload with app-rollout
• Split the app-rollout into multiple and balanced files
![Page 34: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/34.jpg)
Event Binder Strategy
![Page 35: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/35.jpg)
Time to Interactivity
![Page 36: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/36.jpg)
Time to Interactivity
![Page 37: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/37.jpg)
Users should be able to interact with the page at any time
![Page 38: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/38.jpg)
Catch and hold some events until the handler become available
![Page 39: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/39.jpg)
But, doing so without increasing the complexity of the application
![Page 40: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/40.jpg)
yuilibrary.com/gallery/show/event-binder
![Page 41: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/41.jpg)
Event Binder: Features
- Event-driven Module Loading
- Early Event Binding
![Page 42: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/42.jpg)
Event-driven Module Loading
![Page 43: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/43.jpg)
Regular YUI 3 Module
![Page 44: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/44.jpg)
Event-driven Module Loading
![Page 45: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/45.jpg)
Early Event Binding
![Page 46: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/46.jpg)
Early Event Binding
![Page 47: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/47.jpg)
![Page 48: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/48.jpg)
iFrame Strategy
![Page 49: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/49.jpg)
Plug & Play Widgets
![Page 50: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/50.jpg)
A Plug & Play Widget is an independent piece of software that can run on any page
![Page 51: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/51.jpg)
Widgets: Challenges
- Inject the widget without degrading the host page
- Keep the widget JavaScript in a sandbox
- Keep the widget CSS in a sandbox
![Page 52: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/52.jpg)
A YUI instance can be tailored to work off a different document
![Page 53: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/53.jpg)
yuilibrary.com/gallery/show/parent-window
![Page 54: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/54.jpg)
Injecting a widget using an iframe
![Page 55: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/55.jpg)
widget-app-rollout.js
![Page 56: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/56.jpg)
Preload Strategy
![Page 57: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/57.jpg)
http://www.linkedin.com/jsearch
![Page 58: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/58.jpg)
Preload: Features
- Store static JS assets in cache without executing them
- Store static CSS assets in cache without including them
![Page 59: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/59.jpg)
Stay ahead of the users without increasing the complexity of the app
![Page 60: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/60.jpg)
yuilibrary.com/gallery/show/preload
![Page 61: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/61.jpg)
![Page 62: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/62.jpg)
![Page 63: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/63.jpg)
… some more thoughts
- Optimize only if it doesn’t add complexity to your app
- Granularity is good for optimization - Rollouts can help you to control the loading process
- Focus on the bottle necks that affect the majority of your users
- Work on the user perception
![Page 64: JS Loading strategies](https://reader031.fdocuments.net/reader031/viewer/2022012916/5492d012b47959474d8b46da/html5/thumbnails/64.jpg)
Thanks!
Caridy Patinohttp://github.com/caridyhttp://twitter.com/caridy