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

YUI 3 Loading Strategies - YUIConf2010

Embed Size (px)

DESCRIPTION

A robust loading strategy is one of the most important pieces when you think about optimization for high traffic websites. YUI Loader is a wonderful piece of software, and learning how to leverage it is a MUST-HAVE for YUI developers. Dynamic injections, controlling early user interactions, parallel downloads, preloading asssets, and window-iframe loading strategies are some of the topics that Caridy will cover in this presentation.

Citation preview

Page 1: YUI 3 Loading Strategies - YUIConf2010

YUI 3 Loading Strategies

Caridy Patino / @caridyFrontend EngineerYahoo! SearchYUI Evangelist

Page 2: YUI 3 Loading Strategies - YUIConf2010

… since YUIConf 2009

Page 3: YUI 3 Loading Strategies - YUIConf2010

What has changed since 2009?

- YUI().use ( ‘gallery-yui2’ )

Page 4: YUI 3 Loading Strategies - YUIConf2010

What has changed since 2009?

- YUI().use ( ‘gallery-yui2’ )

- YUI 2in3 Project: Y.use(‘yui2-*’)

Page 5: YUI 3 Loading Strategies - YUIConf2010

What has changed since 2009?

- YUI().use ( ‘gallery-yui2’ )

- YUI 2in3 Project: Y.use(‘yui2-*’)

- Conditional loading (e.g., “mod-name-ie”)

Page 6: YUI 3 Loading Strategies - YUIConf2010

What has changed since 2009?

- YUI().use ( ‘gallery-yui2’ )

- YUI 2in3 Project: Y.use(‘yui2-*’)

- Conditional loading (e.g., “mod-name-ie”)

- Fast Boot & _YUI

Page 7: YUI 3 Loading Strategies - YUIConf2010

What has changed since 2009?

- YUI().use ( ‘gallery-yui2’ )

- YUI 2in3 Project: Y.use(‘yui2-*’)

- Conditional loading (e.g., “mod-name-ie”)

- Fast Boot & _YUI

- SimpleYUI

Page 8: YUI 3 Loading Strategies - YUIConf2010

YUI Loading Strategy Evolution

Page 9: YUI 3 Loading Strategies - YUIConf2010
Page 10: YUI 3 Loading Strategies - YUIConf2010
Page 11: YUI 3 Loading Strategies - YUIConf2010

developer.yahoo.com/performance/rules.html

Page 12: YUI 3 Loading Strategies - YUIConf2010
Page 13: YUI 3 Loading Strategies - YUIConf2010

…YUI3 changes the game

Page 14: YUI 3 Loading Strategies - YUIConf2010
Page 15: YUI 3 Loading Strategies - YUIConf2010

YUI < 3.3.0 Loader Limitations

- Concurrent loading

- Queueing and aggregation

Page 16: YUI 3 Loading Strategies - YUIConf2010
Page 17: YUI 3 Loading Strategies - YUIConf2010
Page 18: YUI 3 Loading Strategies - YUIConf2010

dd, substitute and slider

tabview, oop, event, node, widget, etc

yui seed

loader

Page 19: YUI 3 Loading Strategies - YUIConf2010

Static Combo Strategy

Page 20: YUI 3 Loading Strategies - YUIConf2010
Page 21: YUI 3 Loading Strategies - YUIConf2010
Page 22: YUI 3 Loading Strategies - YUIConf2010

Data-driven initialization routine

Page 23: YUI 3 Loading Strategies - YUIConf2010

Using app-rollout files

Page 24: YUI 3 Loading Strategies - YUIConf2010

Using app-rollout files

Page 25: YUI 3 Loading Strategies - YUIConf2010

Rollout vs Y.use()

Page 26: YUI 3 Loading Strategies - YUIConf2010

Rollout Composition

YUI Core

Gallery

2in3

CustomInit.js

Page 27: YUI 3 Loading Strategies - YUIConf2010

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

Page 28: YUI 3 Loading Strategies - YUIConf2010

SimpleYUI is a rollout

Page 29: YUI 3 Loading Strategies - YUIConf2010

github.com/yui/yui3/tree/master/src/simpleyui/concat.sh

Page 30: YUI 3 Loading Strategies - YUIConf2010

Interactivity Core & Lazy Components

Page 31: YUI 3 Loading Strategies - YUIConf2010
Page 32: YUI 3 Loading Strategies - YUIConf2010

Defining the interactivity core will help to reduce the app-rollout size through lazy components

Page 33: YUI 3 Loading Strategies - YUIConf2010
Page 34: YUI 3 Loading Strategies - YUIConf2010

Core and Lazy Components

core rollout

lazy components

Page 35: YUI 3 Loading Strategies - YUIConf2010

Parallel Download Strategy

Page 36: YUI 3 Loading Strategies - YUIConf2010
Page 37: YUI 3 Loading Strategies - YUIConf2010

Get app-rollout early without compromising domready and onload

Page 38: YUI 3 Loading Strategies - YUIConf2010

“Ideal Solution”

Page 39: YUI 3 Loading Strategies - YUIConf2010
Page 40: YUI 3 Loading Strategies - YUIConf2010

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 41: YUI 3 Loading Strategies - YUIConf2010

Event Binder Strategy

Page 42: YUI 3 Loading Strategies - YUIConf2010

Time to Interactivity

Page 43: YUI 3 Loading Strategies - YUIConf2010

Timeline

Page 44: YUI 3 Loading Strategies - YUIConf2010

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

Page 45: YUI 3 Loading Strategies - YUIConf2010

Catch and hold some events until the handler become available

Page 46: YUI 3 Loading Strategies - YUIConf2010

But, doing so without increasing the complexity of the application

Page 47: YUI 3 Loading Strategies - YUIConf2010

yuilibrary.com/gallery/show/event-binder

Page 48: YUI 3 Loading Strategies - YUIConf2010

Event Binder: Features

- Event-driven Module Loading

- Early Event Binding

Page 49: YUI 3 Loading Strategies - YUIConf2010

Event-driven Module Loading

Page 50: YUI 3 Loading Strategies - YUIConf2010

Regular YUI 3 Module

Page 51: YUI 3 Loading Strategies - YUIConf2010

Event-driven Module Loading

Page 52: YUI 3 Loading Strategies - YUIConf2010

Early Event Binding

Page 53: YUI 3 Loading Strategies - YUIConf2010

Early Event Binding

Page 54: YUI 3 Loading Strategies - YUIConf2010
Page 55: YUI 3 Loading Strategies - YUIConf2010

iFrame Strategy

Page 56: YUI 3 Loading Strategies - YUIConf2010

Plug & Play Widgets

Page 57: YUI 3 Loading Strategies - YUIConf2010

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

Page 58: YUI 3 Loading Strategies - YUIConf2010

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 59: YUI 3 Loading Strategies - YUIConf2010

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

Page 60: YUI 3 Loading Strategies - YUIConf2010

yuilibrary.com/gallery/show/parent-window

Page 61: YUI 3 Loading Strategies - YUIConf2010

Injecting a widget using an iframe

Page 62: YUI 3 Loading Strategies - YUIConf2010

widget-app-rollout.js

Page 63: YUI 3 Loading Strategies - YUIConf2010

Modules using document and window

Use “Y.config.win” and “Y.config.doc” instead.

/var/node/yui3-gallery/src15:25:59 none:src $ grep -rinl "document\." */js/*.js

gallery-accordion/js/gallery-accordion-item.jsgallery-accordion/js/gallery-accordion.jsgallery-aui-autocomplete/js/gallery-aui-autocomplete.jsgallery-aui-base/js/gallery-aui-core.jsgallery-aui-chart/js/gallery-aui-chart.jsgallery-aui-color/js/gallery-aui-color.jsgallery-aui-dialog/js/gallery-aui-dialog.jsgallery-aui-editable/js/gallery-aui-editable.js.jsgallery-boxshadow-anim/js/boxshadow-anim.jsgallery-charts/js/Renderer.jsgallery-dimensions/js/Dimensions.jsgallery-event-pasted/js/pasted.jsgallery-exprbuilder/js/ExpressionBuilder.jsgallery-formvalidator/js/BaseInputField.jsgallery-lightbox/js/lightbox.jsgallery-modernizr/js/modernizr.jsgallery-notifications/js/notifications.jsgallery-overlay-extras/js/overlay-extras.jsgallery-overlay-modal/js/overlay-modal.jsgallery-scrollintoview/js/ScrollIntoView.jsgallery-simple-editor/js/simple-editor.jsgallery-simple-editor/js/toolbar.jsgallery-speedns/js/speedns.jsgallery-stalker/js/gallery-stalker.jsgallery-tabby/js/tabby.jsgallery-textarea-counter/js/textarea-counter.jsgallery-treeview/js/Node.jsgallery-treeview/js/TextNode.jsgallery-treeview/js/TreeViewEd.jsgallery-treeview/js/TreeView.js

/var/node/yui3-gallery/src15:28:13 none:src $ grep -rinl "window\." */js/*.js

gallery-aui-node-html5-print/js/gallery-aui-node-html5-print.jsgallery-beforeunload/js/beforeunload.jsgallery-history-lite/js/history-lite.jsgallery-markout/js/markout.jsgallery-modernizr/js/modernizr.jsgallery-notifications/js/notifications.jsgallery-parent-window/js/gallery-parent-window.jsgallery-sandbox/js/sandbox.jsgallery-scrollintoview/js/ScrollIntoView.jsgallery-shoveler/js/shoveler.jsgallery-simple-editor/js/simple-editor.jsgallery-treeview/js/TreeView.js

Page 64: YUI 3 Loading Strategies - YUIConf2010

…a mental note

Page 65: YUI 3 Loading Strategies - YUIConf2010
Page 66: YUI 3 Loading Strategies - YUIConf2010

… 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 67: YUI 3 Loading Strategies - YUIConf2010

Thanks!

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

Page 68: YUI 3 Loading Strategies - YUIConf2010

Bonus Section

Page 69: YUI 3 Loading Strategies - YUIConf2010

Preload Strategy

Page 70: YUI 3 Loading Strategies - YUIConf2010
Page 71: YUI 3 Loading Strategies - YUIConf2010

http://www.linkedin.com/jsearch

Page 72: YUI 3 Loading Strategies - YUIConf2010

Preload: Features

- Store static JS assets in cache without executing them

- Store static CSS assets in cache without including them

Page 73: YUI 3 Loading Strategies - YUIConf2010

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

Page 74: YUI 3 Loading Strategies - YUIConf2010

yuilibrary.com/gallery/show/preload

Page 75: YUI 3 Loading Strategies - YUIConf2010
Page 76: YUI 3 Loading Strategies - YUIConf2010
Page 77: YUI 3 Loading Strategies - YUIConf2010

Preload: Implementation

- (new Image()).src = f; // for IE

- doc.createElement('object').data = f; // for others

- Stoyan: Preload CSS/JS without execution http://www.phpied.com/preload-cssjavascript-without-execution/

- Stoyan: Preload, then execute http://www.phpied.com/preload-then-execute/