64
YUI 3 Loading Strategies Caridy Patino / @caridy Frontend Engineer Yahoo! Search YUI Evangelist

JS Loading strategies

Embed Size (px)

DESCRIPTION

Faster web sites attract more users, engage them longer, and decrease the abandon rate drastically.In the quest for making a website faster, a solid loading strategy is an important vector. Dynamic injections, controlling early user interactions, parallel downloads, preloading, and iframe-loader are all well established strategies that you can use to improve performance. Knowing them iscritical for success, specially for complex web applications.Things you will learn from this presentation:a) Why picking up the right loading strategy is important.b) Different strategies that you can use today.c) Different tools under the YUI umbrella that you can use today.

Citation preview

Page 1: JS Loading strategies

YUI 3 Loading Strategies

Caridy Patino / @caridyFrontend EngineerYahoo! SearchYUI Evangelist

Page 2: JS Loading strategies

Evolution

Page 3: JS Loading strategies
Page 4: JS Loading strategies
Page 5: JS Loading strategies

developer.yahoo.com/performance/rules.html

Page 6: JS Loading strategies

Put Scripts at Bottom

Page 7: JS Loading strategies

Minimize HTTP Requests

Page 8: JS Loading strategies

Use a Content Delivery Network (CDN)

Page 9: JS Loading strategies
Page 10: JS Loading strategies

JS Loader Frameworks changed the game

Page 11: JS Loading strategies

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
Page 13: JS Loading strategies

dd, substitute and slider

tabview, oop, event, node, widget, etc

yui seed

loader

Page 14: JS Loading strategies

Static Combo Strategy

Page 15: JS Loading strategies
Page 16: JS Loading strategies
Page 17: JS Loading strategies

Data-driven initialization routine

Page 18: JS Loading strategies

Using app-rollout files

Page 19: JS Loading strategies

Using app-rollout files

Page 20: JS Loading strategies

Rollout vs Loader

Page 21: JS Loading strategies

Rollout Composition

Library

Plugins

CustomInit.js

Page 22: JS Loading strategies

A big app-rollout takes more time to download and can potentially freeze the browser

Page 23: JS Loading strategies

Simple rollout

Page 24: JS Loading strategies

Interactivity Core & Lazy Components

Page 25: JS Loading strategies
Page 26: JS Loading strategies

Defining the interactivity core is

crucial

Page 27: JS Loading strategies
Page 28: JS Loading strategies

Core and Lazy Components

core rollout

lazy components

Page 29: JS Loading strategies

Parallel Download Strategy

Page 30: JS Loading strategies

Get app-rollout early without compromising domready and onload

Page 31: JS Loading strategies

“Ideal Solution”

Page 32: JS Loading strategies
Page 33: JS Loading strategies

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

Event Binder Strategy

Page 35: JS Loading strategies

Time to Interactivity

Page 36: JS Loading strategies

Time to Interactivity

Page 37: JS Loading strategies

Users should be able to interact with the page at any time

Page 38: JS Loading strategies

Catch and hold some events until the handler become available

Page 39: JS Loading strategies

But, doing so without increasing the complexity of the application

Page 40: JS Loading strategies

yuilibrary.com/gallery/show/event-binder

Page 41: JS Loading strategies

Event Binder: Features

- Event-driven Module Loading

- Early Event Binding

Page 42: JS Loading strategies

Event-driven Module Loading

Page 43: JS Loading strategies

Regular YUI 3 Module

Page 44: JS Loading strategies

Event-driven Module Loading

Page 45: JS Loading strategies

Early Event Binding

Page 46: JS Loading strategies

Early Event Binding

Page 47: JS Loading strategies
Page 48: JS Loading strategies

iFrame Strategy

Page 49: JS Loading strategies

Plug & Play Widgets

Page 50: JS Loading strategies

A Plug & Play Widget is an independent piece of software that can run on any page

Page 51: JS Loading strategies

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

A YUI instance can be tailored to work off a different document

Page 53: JS Loading strategies

yuilibrary.com/gallery/show/parent-window

Page 54: JS Loading strategies

Injecting a widget using an iframe

Page 55: JS Loading strategies

widget-app-rollout.js

Page 56: JS Loading strategies

Preload Strategy

Page 57: JS Loading strategies

http://www.linkedin.com/jsearch

Page 58: JS Loading strategies

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

Stay ahead of the users without increasing the complexity of the app

Page 60: JS Loading strategies

yuilibrary.com/gallery/show/preload

Page 61: JS Loading strategies
Page 62: JS Loading strategies
Page 63: JS Loading strategies

… 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

Thanks!

Caridy Patinohttp://github.com/caridyhttp://twitter.com/caridy