61
Your script just killed my site stevesouders.com/docs/paypal-spof-20121115.pptx Disclaimer: This content does not necessarily reflect the opinions of my employer.

"Your script just killed my site" by Steve Souders

Embed Size (px)

Citation preview

Page 1: "Your script just killed my site" by Steve Souders

Your script just killed my

site

stevesouders.com/docs/paypal-spof-20121115.pptxDisclaimer: This content does not necessarily reflect the opinions of my employer.

Page 2: "Your script just killed my site" by Steve Souders

SPOF

Page 3: "Your script just killed my site" by Steve Souders
Page 4: "Your script just killed my site" by Steve Souders
Page 5: "Your script just killed my site" by Steve Souders

synchronous scripts block all following

elements from rendering

in all browsers

Page 6: "Your script just killed my site" by Steve Souders

#fail

Page 7: "Your script just killed my site" by Steve Souders

async

#fail

async

async

sync

Page 8: "Your script just killed my site" by Steve Souders

Frontend SPOF

Page 9: "Your script just killed my site" by Steve Souders

http://www.webpagetest.org/result/120529_41_HWV/

Page 10: "Your script just killed my site" by Steve Souders
Page 11: "Your script just killed my site" by Steve Souders

entire BODY blocked from rendering

Page 12: "Your script just killed my site" by Steve Souders

http://www.webpagetest.org/result/120529_41_HWV/

Page 13: "Your script just killed my site" by Steve Souders
Page 14: "Your script just killed my site" by Steve Souders

mysql>

Page 15: "Your script just killed my site" by Steve Souders

select p.url, wptid mysql>

Page 16: "Your script just killed my site" by Steve Souders

select p.url, wptid

from pages as p, requests as r mysql>

Page 17: "Your script just killed my site" by Steve Souders

select p.url, wptid

from pages as p, requests as r

where p.pageid >= 844954 and

p.pageid <= 1564447 and

p.pageid = r.pageid and

mysql>

Page 18: "Your script just killed my site" by Steve Souders

select p.url, wptid

from pages as p, requests as r

where p.pageid >= 844954 and

p.pageid <= 1564447 and

p.pageid = r.pageid and

rank < 20000 and

mysql>

Page 19: "Your script just killed my site" by Steve Souders

select p.url, wptid

from pages as p, requests as r

where p.pageid >= 844954 and

p.pageid <= 1564447 and

p.pageid = r.pageid and

rank < 20000 and

resp_content_type like “%script%” and

mysql>

Page 20: "Your script just killed my site" by Steve Souders

select p.url, wptid

from pages as p, requests as r

where p.pageid >= 844954 and

p.pageid <= 1564447 and

p.pageid = r.pageid and

rank < 20000 and

resp_content_type like “%script%” and

time > 10000 and

mysql>

Page 21: "Your script just killed my site" by Steve Souders

select p.url, wptid

from pages as p, requests as r

where p.pageid >= 844954 and

p.pageid <= 1564447 and

p.pageid = r.pageid and

rank < 20000 and

resp_content_type like “%script%” and

time > 10000 and

renderStart > 10000

mysql>

Page 22: "Your script just killed my site" by Steve Souders

select p.url, wptid

from pages as p, requests as r

where p.pageid >= 844954 and

p.pageid <= 1564447 and

p.pageid = r.pageid and

rank < 20000 and

resp_content_type like “%script%” and

time > 10000 and

renderStart > 10000

group by p.pageid;

mysql>

Page 23: "Your script just killed my site" by Steve Souders
Page 24: "Your script just killed my site" by Steve Souders
Page 25: "Your script just killed my site" by Steve Souders
Page 26: "Your script just killed my site" by Steve Souders
Page 27: "Your script just killed my site" by Steve Souders
Page 28: "Your script just killed my site" by Steve Souders

blog.catchpoint.com/2012/06/01/facebook-outage-wake-up-call-for-websites/

Page 29: "Your script just killed my site" by Steve Souders
Page 30: "Your script just killed my site" by Steve Souders
Page 31: "Your script just killed my site" by Steve Souders
Page 32: "Your script just killed my site" by Steve Souders
Page 33: "Your script just killed my site" by Steve Souders
Page 34: "Your script just killed my site" by Steve Souders
Page 35: "Your script just killed my site" by Steve Souders

async!

Page 36: "Your script just killed my site" by Steve Souders
Page 37: "Your script just killed my site" by Steve Souders

async!

#failsync

Page 38: "Your script just killed my site" by Steve Souders
Page 39: "Your script just killed my site" by Steve Souders
Page 40: "Your script just killed my site" by Steve Souders

While placing JavaScript files at the bottom of the page is a best practice for

website performance, when including the anywhere.js file, always place the file

as close to the top of the page as possible.

The anywhere.js file is small (<3KB) and is delivered to the page GZIP'd.

Further, all dependancies for @Anywhere features are loaded

asynchronously, on-demand so as to not impact performance of the host page.

Page 41: "Your script just killed my site" by Steve Souders

three facts:

1. failures happen

2. 304 & 200 both produce frontend SPOF

3. anywhere.js expires after 15 minutes

Page 42: "Your script just killed my site" by Steve Souders

snippet cache timeshttp://platform.twitter.com/widgets.js - 30 mins

http://connect.facebook.net/en_US/all.js - 15 mins

http://www.google-analytics.com/ga.js - 120 mins

Page 43: "Your script just killed my site" by Steve Souders

“bootstrap scripts” often have short cache times

more frequent Conditional GET requests means frontend SPOF is more likely

but short cache times is the only way snippet owners can push updates

or is it?

Page 44: "Your script just killed my site" by Steve Souders

self-updating bootstrap scripts

stevesouders.com/blog/2012/05/22/self-updating-scripts/

with Stoyan Stefanov

Page 45: "Your script just killed my site" by Steve Souders

bootstrap.js:

var v=“1.7”;

scriptelem.src = “beacon.js?

v=”+v;

client server

current version is 1.7

200

beacon.js: ?v=1.7&log...

204

maxage=604800

Page 46: "Your script just killed my site" by Steve Souders

bootstrap.js:

client server

bootstrap.js updated to

1.8

beacon.js: ?v=1.7&log...

200

read from cache

var iframe1 = document.createElement("iframe");

iframe1.style.display = "none”;

iframe1.src = ”update.php";

document.body.appendChild(iframe1);

next day…

Page 47: "Your script just killed my site" by Steve Souders

update.php

client server

<script src=“bootstrap.js">

</script>

<script>

if (location.hash === '') {

location.hash = "check”;

location.reload(true);

}

</script>on reload bootstrap.js is re-

requested and overwrites

cache

200

200

bootstrap.js is still read from

cache

Page 48: "Your script just killed my site" by Steve Souders

bootstrap scripts can have long cache times

AND

get updated when necessary

voilà

Page 49: "Your script just killed my site" by Steve Souders

the update is used on the next page view (like

app cache)

caveat

Page 50: "Your script just killed my site" by Steve Souders

lognormal.com/blog/2012/06/05/updating-cached-boomerang/

Page 51: "Your script just killed my site" by Steve Souders

lognormal.com/blog/2012/06/05/updating-cached-boomerang/

Page 52: "Your script just killed my site" by Steve Souders

dynamic symbol loading: C

void *handle;double (*cosine)(double);

handle = dlopen("/lib/libm.so.6", RTLD_LAZY);if ( !handle ) { exit(1);}

cosine = dlsym(handle, "cos");if ( dlerror() != NULL ) { exit(1);}

Page 53: "Your script just killed my site" by Steve Souders

dynamic symbol loading: JavaScript

<script src='mycombo.js'></script>

<script>$('.content a, .huffpo-wide-container a').mousedown(function() {...

</script>

Wha?!

Page 54: "Your script just killed my site" by Steve Souders

ejohn.org/blog/degrading-script-tags/

Page 55: "Your script just killed my site" by Steve Souders

dynamic symbol loading: JavaScript

<script src='mycombo.js'></script>

<script>$('.content a, .huffpo-wide-container a').mousedown(function() {...

</script>

<script src='mycombo.js'>

$('.content a, .huffpo-wide-container a').mousedown(function() {...

</script>

at the end of mycombo.js:

var scripts = document.getElementsByTagName("script");

for ( var cntr = scripts.length; cntr > 0; cntr-- ) {

var curScript = scripts[cntr-1];

if (curScript.src.indexOf('mycombo.js') != -1) {

eval( curScript.innerHTML );

break;

}

}

Page 56: "Your script just killed my site" by Steve Souders

& we mean business

we’re JavaScript

Page 57: "Your script just killed my site" by Steve Souders

load 3rd party scripts async

test with WebPagetest SPOF

have RUM timeout

self-update bootstrap scripts & increase cache times

harden JS loading

takeaways

Page 58: "Your script just killed my site" by Steve Souders

what’s your website’s weakest

link?

Page 59: "Your script just killed my site" by Steve Souders

Steve Souders

@souders

stevesouders.com/docs/paypal-spof-20121115.pptx

Page 60: "Your script just killed my site" by Steve Souders
Page 61: "Your script just killed my site" by Steve Souders

Patrick Meenan

Nicholas Zakas

Guy Podjarny

Stoyan Stefanov

Tim Kadlec

Brian Pane

Josh Fraser

Steve Souders

Betty Tso

Israel Nir

Marcel Duran

Éric Daspet

Alois Reitbauer

Matthew Prince

Buddy Brewer

Alexander Podelko

Estelle Weyl

Aaron Peters

Tony Gentilcore

Matthew Steele

Bryan McQuade

Tobie LangelBilly Hoffman

Joshua Bixby

Sergey Chernyshev

JP Castro

Pavel Paulau

David Calhoun

Nicole Sullivan

James Pearce

Tom Hughes-Croucher