introduction to resourceloader - wikimedia · wikimania 2011 roan kattouw - timo tijhof - trevor...

58
WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to ResourceLoader Focus on easy gains for Speed, localization and developer-friendliness

Upload: others

Post on 17-Jul-2020

20 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Roan Kattouw - Timo Tijhof -

Trevor Parscal -

[[User:Catrope]][[User:Krinkle]][[User:Trevor Parscal]]

Introduction to ResourceLoaderFocus on easy gains for

Speed, localization and developer-friendliness

Page 2: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Page 3: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Resources

0KB 100KB 200KB 300KB 400KB 500KB 600KB

HTML JavaScript CSS Images

Page 4: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Resources

0KB 100KB 200KB 300KB 400KB 500KB 600KB

HTML JavaScript CSS Images

1

Page 5: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Resources

0KB 100KB 200KB 300KB 400KB 500KB 600KB

HTML JavaScript CSS Images

1 29

Page 6: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Resources

0KB 100KB 200KB 300KB 400KB 500KB 600KB

HTML JavaScript CSS Images

1 29 4

Page 7: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Resources

0KB 100KB 200KB 300KB 400KB 500KB 600KB

HTML JavaScript CSS Images

1 2229 4

Page 8: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Resources

0KB 100KB 200KB 300KB 400KB 500KB 600KB

HTML JavaScript CSS Images

1 47 2

Page 9: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Modules

Page 10: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Modules

Scripts,

Page 11: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Modules

Scripts, styles

Page 12: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Modules

Scripts,

& messages

styles

Page 13: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Modules

Scripts, styles

& messages

Page 14: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Modules

Page 15: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Modules

b ca

a, b & c

Page 16: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Modules

b ca

a, b & c

Page 17: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Modules

bcaa, b & c

Page 18: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Modules

a, b & c

Page 19: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Modules

Page 20: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: Register a module

Page 21: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: Register a module$wgResourceModules['ext.Foobar'] = array(

Page 22: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: Register a module$wgResourceModules['ext.Foobar'] = array(

'scripts' => 'resources/ext.Foobar.js',

Page 23: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: Register a module$wgResourceModules['ext.Foobar'] = array(

'scripts' => 'resources/ext.Foobar.js','styles' => 'resources/ext.Foobar.css',

Page 24: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: Register a module$wgResourceModules['ext.Foobar'] = array(

'scripts' => 'resources/ext.Foobar.js','styles' => 'resources/ext.Foobar.css','messages' => array(

'foobar-title','foobar-welcome','foobar-intro',

),

Page 25: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: Register a module$wgResourceModules['ext.Foobar'] = array(

'scripts' => 'resources/ext.Foobar.js','styles' => 'resources/ext.Foobar.css','messages' => array(

'foobar-title','foobar-welcome','foobar-intro',

),'dependencies' => array(

'jquery.ui.button','mediawiki.Title',

),);

Page 26: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Images: Sprites. No ?

Page 27: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Images: Sprites. No ?

Page 28: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Images: Sprites. No ?

Page 29: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Images: Sprites. No ?

Page 30: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Images: Sprites. No ?

Page 31: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Images: Sprites. No ?

Page 32: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

CSS: Data URI embedding

Page 33: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

CSS: Data URI embedding

.foo {/* @embed */background-image: url(foo.png);

}

Page 34: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

CSS: Data URI embedding

.foo {/* @embed */background-image: url(foo.png);

}

.foo {background-image: url(data:image/png;base64,iVBORw0K...FTkSuQmCC);

}

Page 35: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

CSS: Flipping for RTL languages

Page 36: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

CSS: Flipping for RTL languages.foo {float: left;padding-right: 0.5em;margin: 1px 2px 3px 4px;background-image: url(foo-ltr.png);

}

Page 37: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

CSS: Flipping for RTL languages.foo {float: left;padding-right: 0.5em;margin: 1px 2px 3px 4px;background-image: url(foo-ltr.png);

}

.foo {float: right;padding-left: 0.5em;margin: 1px 4px 3px 2px;background-image: url(foo-rtl.png);

}

Page 38: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Page 39: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Page 40: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Startup Module

Page 41: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Startup Module

if ( IE5 ) { giveUp(); }

Sanity check

Page 42: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Startup Module

if ( IE5 ) { giveUp(); }

Sanity checkmodule manifest

Dependencies

b c

a

d e

Page 43: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Startup Module

site-wide settings

Configurationif ( IE5 ) { giveUp(); }

Sanity checkmodule manifest

Dependencies

b c

a

d e

Page 44: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Client-side Loader

Page 45: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Client-side Loader

calculate dependencies

Resolution

b c

a

Page 46: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Client-side Loader

calculate dependencies

Resolution

b c

a

give it to me all at once

Batching

ca +

Page 47: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Client-side Loader

calculate dependencies

Resolution

b c

a

give it to me all at once

Batching

ca +

run in correct order

Execution

a

Page 48: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: JavaScript wrapping

Page 49: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: JavaScript wrappingmw.loader.implement( 'foo',

Page 50: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: JavaScript wrappingmw.loader.implement( 'foo',

function() {! ! // Code for foo module

mw.Foo = { ... };! },

Page 51: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: JavaScript wrappingmw.loader.implement( 'foo',

function() {! ! // Code for foo module

mw.Foo = { ... };! },

// CSS for foo module

Page 52: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: JavaScript wrappingmw.loader.implement( 'foo',

function() {! ! // Code for foo module

mw.Foo = { ... };! },

// CSS for foo module{

! ! 'all': '.foo{color:blue;background-image:url(data:image/png;base64,iVBORw0K...FTkSuQmCC);}',! ! 'print': '.foo{display:none;}'! },

Page 53: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: JavaScript wrappingmw.loader.implement( 'foo',

function() {! ! // Code for foo module

mw.Foo = { ... };! },

// CSS for foo module{

! ! 'all': '.foo{color:blue;background-image:url(data:image/png;base64,iVBORw0K...FTkSuQmCC);}',! ! 'print': '.foo{display:none;}'! },

// messages for foo module

Page 54: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: JavaScript wrappingmw.loader.implement( 'foo',

function() {! ! // Code for foo module

mw.Foo = { ... };! },

// CSS for foo module{

! ! 'all': '.foo{color:blue;background-image:url(data:image/png;base64,iVBORw0K...FTkSuQmCC);}',! ! 'print': '.foo{display:none;}'! },

// messages for foo module{

! ! 'foo-intro': 'This is an introduction to foo.',! ! 'foo-msg': 'Hello $1, check out $2!'! });

Page 55: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: Module loading

Page 56: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: Module loading

//example.org/w/load.php?modules=foo|bar&skin=vector&lang=en

Page 57: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Example: Module loading

//example.org/w/load.php?modules=foo|bar&skin=vector&lang=en

mw.loader.implement('foo',function(){mw.Foo={};},{'all':'.foo{color:blue;background-image:url(data:image/png;base64,iVBORw0K...FTkSuQmCC);}','print':'.foo{display:none;}'},{'foo-intro':'This is an introduction to foo.','foo-msg':'Hello $1, check out $2!'});mw.loader.implement('bar',...);

Page 58: Introduction to ResourceLoader - Wikimedia · WIKIMANIA 2011 Roan Kattouw - Timo Tijhof - Trevor Parscal - [[User:Catrope]] [[User:Krinkle]] [[User:Trevor Parscal]] Introduction to

WIKIMANIA 2011

Thanks!

http://wikitech.wikimedia.org/view/Presentations

http://bit.ly/wm11resourceloader

http://www.mediawiki.org/wiki/ResourceLoader

Roan Kattouw - Timo Tijhof -

Trevor Parscal -

[[User:Catrope]][[User:Krinkle]][[User:Trevor Parscal]]