high performance web sites, with ads: don't let third parties make you slow

79
HIGH PERFORMANCE WEB SITES, WITH ADS – Don't let third parties make you slow Tobias Järlund [email protected] @jarlund

Upload: tobias-jaerlund

Post on 28-Nov-2014

9.981 views

Category:

Technology


0 download

DESCRIPTION

My presentation from Disruptive Code

TRANSCRIPT

Page 1: High Performance Web Sites, With Ads: Don't let third parties make you slow

HIGH PERFORMANCE WEB SITES, WITH ADS– Don't let third parties make you slow

Tobias Jä[email protected]@jarlund

Page 2: High Performance Web Sites, With Ads: Don't let third parties make you slow
Page 3: High Performance Web Sites, With Ads: Don't let third parties make you slow

Aftonbladet.se

”The primary news source of the Swedish people”

The largest website in Sweden5.6 million visitors/week, 2.4 million visitors/day

Loooong pages, with a lot of ad positions

Page 4: High Performance Web Sites, With Ads: Don't let third parties make you slow

WEB PERFORMANCEOPTIMIZATION

Page 5: High Performance Web Sites, With Ads: Don't let third parties make you slow

THE USUAL STUFF-Make Fewer HTTP Requests-Use a Content Delivery Network (CDN)-Add Expires or Cache-Control Header-Gzip Components-Put Stylesheets at Top-Put Scripts at Bottom-Avoid CSS Expressions-Make JavaScript and CSS External-Reduce DNS Lookups-Minify JavaScript and CSS-Avoid Redirects-Remove Duplicate Scripts-Configure ETags-Make Ajax Cacheable-Flush Buffer Early-Use GET for Ajax Requests-Postload Components-Preload Components

-Reduce the Number of DOM Elements-Split Components Across Domains-Minimize Number of Iframes-Avoid 404s-Reduce Cookie Size-Use Cookie-Free Domains for Components-Minimize DOM Access-Develop Smart Event Handlers-Choose <link> Over @import-Avoid Filters-Optimize Images-Optimize CSS Sprites-Do Not Scale Images in HTML-Make favicon.ico Small and Cacheable-Keep Components Under 25 KB-Pack Components Into a Multipart Document-Avoid Empty Image src

http://developer.yahoo.com/performance/rules.html

Page 6: High Performance Web Sites, With Ads: Don't let third parties make you slow

THE USUAL STUFF-Make Fewer HTTP Requests-Use a Content Delivery Network (CDN)-Add Expires or Cache-Control Header-Gzip Components-Put Stylesheets at Top-Put Scripts at Bottom-Avoid CSS Expressions-Make JavaScript and CSS External-Reduce DNS Lookups-Minify JavaScript and CSS-Avoid Redirects-Remove Duplicate Scripts-Configure ETags-Make Ajax Cacheable-Flush Buffer Early-Use GET for Ajax Requests-Postload Components-Preload Components

-Reduce the Number of DOM Elements-Split Components Across Domains-Minimize Number of Iframes-Avoid 404s-Reduce Cookie Size-Use Cookie-Free Domains for Components-Minimize DOM Access-Develop Smart Event Handlers-Choose <link> Over @import-Avoid Filters-Optimize Images-Optimize CSS Sprites-Do Not Scale Images in HTML-Make favicon.ico Small and Cacheable-Keep Components Under 25 KB-Pack Components Into a Multipart Document-Avoid Empty Image src

http://developer.yahoo.com/performance/rules.html

Page 7: High Performance Web Sites, With Ads: Don't let third parties make you slow

WHEN THAT DOESN'T HELP?

Page 8: High Performance Web Sites, With Ads: Don't let third parties make you slow

ADS

Page 9: High Performance Web Sites, With Ads: Don't let third parties make you slow

ADS = ?Copyrighted image ofJimmie Åkesson

Page 10: High Performance Web Sites, With Ads: Don't let third parties make you slow

ADS = ?Copyrighted image ofFredrik Reinfeldt

Page 11: High Performance Web Sites, With Ads: Don't let third parties make you slow

IFRAMES OR JAVASCRIPT

Page 12: High Performance Web Sites, With Ads: Don't let third parties make you slow

IFRAMES OR JAVASCRIPT-May load in parallel-Possible to late-load-Browser sandbox-Fixed width/height-Adds overhead-No access to the DOM

Page 13: High Performance Web Sites, With Ads: Don't let third parties make you slow

IFRAMES OR JAVASCRIPT-May load in parallel-Possible to late-load-Browser sandbox-Fixed width/height-Adds overhead-No access to the DOM

-Full access to the DOM-Supports all types of ads-Blocks rendering/download-Not possible to late-load-Full access to the DOM

Page 14: High Performance Web Sites, With Ads: Don't let third parties make you slow

IFRAMES OR JAVASCRIPT-May load in parallel-Possible to late-load-Browser sandbox-Fixed width/height-Adds overhead-No access to the DOM

-Full access to the DOM-Supports all types of ads-Blocks rendering/download-Not possible to late-load-Full access to the DOM

-Supports all types of ads

Page 15: High Performance Web Sites, With Ads: Don't let third parties make you slow

<script src="http://a.."></script>

Page 16: High Performance Web Sites, With Ads: Don't let third parties make you slow

<script src="http://a.."></script>document.write('<img src="http://example.com/ad.gif">');

Page 17: High Performance Web Sites, With Ads: Don't let third parties make you slow

<script src="http://a.."></script>document.write('<img src="http://example.com/ad.gif">');

<img src="http://example.com/ad.gif>

Page 18: High Performance Web Sites, With Ads: Don't let third parties make you slow

<script src="http://a.."></script>

Page 19: High Performance Web Sites, With Ads: Don't let third parties make you slow

<script src="http://a.."></script>document.write('<script src="http://b.."></script>');

Page 20: High Performance Web Sites, With Ads: Don't let third parties make you slow

<script src="http://a.."></script>document.write('<script src="http://b.."></script>');

<script src="http://b.."></script>

Page 21: High Performance Web Sites, With Ads: Don't let third parties make you slow

<script src="http://a.."></script>document.write('<script src="http://b.."></script>');

<script src="http://b.."></script>document.write('<script src="http://c.."></script>');

Page 22: High Performance Web Sites, With Ads: Don't let third parties make you slow

<script src="http://a.."></script>document.write('<script src="http://b.."></script>');

<script src="http://b.."></script>document.write('<script src="http://c.."></script>');

<script src="http://c.."></script>

Page 23: High Performance Web Sites, With Ads: Don't let third parties make you slow

<script src="http://a.."></script>document.write('<script src="http://b.."></script>');

<script src="http://b.."></script>document.write('<script src="http://c.."></script>');

<script src="http://c.."></script>document.write('<script src="http://d.."></script>');

Page 24: High Performance Web Sites, With Ads: Don't let third parties make you slow

<script src="http://a.."></script>document.write('<script src="http://b.."></script>');

<script src="http://b.."></script>document.write('<script src="http://c.."></script>');

<script src="http://c.."></script>document.write('<script src="http://d.."></script>');

<script src="http://d.."></script>

Page 25: High Performance Web Sites, With Ads: Don't let third parties make you slow

<script src="http://a.."></script>document.write('<script src="http://b.."></script>');

<script src="http://b.."></script>document.write('<script src="http://c.."></script>');

<script src="http://c.."></script>document.write('<script src="http://d.."></script>');

<script src="http://d.."></script>document.write('<img src="http://example.com/ad.gif">');

Page 26: High Performance Web Sites, With Ads: Don't let third parties make you slow

<script src="http://a.."></script>document.write('<script src="http://b.."></script>');

<script src="http://b.."></script>document.write('<script src="http://c.."></script>');

<script src="http://c.."></script>document.write('<script src="http://d.."></script>');

<script src="http://d.."></script>document.write('<img src="http://example.com/ad.gif">');

<img src="http://example.com/ad.gif>

Page 30: High Performance Web Sites, With Ads: Don't let third parties make you slow

HTML page

http://www.webpagetest.org/

Ad network 1 Ad network 2

Page 31: High Performance Web Sites, With Ads: Don't let third parties make you slow

HTML page

http://www.webpagetest.org/

Ad network 1 Ad network 2

Actual ad

Page 32: High Performance Web Sites, With Ads: Don't let third parties make you slow

HTML page

http://www.webpagetest.org/

Ad network 1 Ad network 2

Actual ad

Rest of the page

Page 33: High Performance Web Sites, With Ads: Don't let third parties make you slow

HTML page

http://www.webpagetest.org/

Ad network 1 Ad network 2

Actual ad

Rest of the page

Page rendering blocked by ad

Page 35: High Performance Web Sites, With Ads: Don't let third parties make you slow

IS THERE A BETTER SOLUTION?

Page 36: High Performance Web Sites, With Ads: Don't let third parties make you slow

I GOOGLED THE NET

Page 37: High Performance Web Sites, With Ads: Don't let third parties make you slow

16 TECHNIQUES

Page 38: High Performance Web Sites, With Ads: Don't let third parties make you slow

16 TECHNIQUES

14 BROKEN

Page 39: High Performance Web Sites, With Ads: Don't let third parties make you slow

16 TECHNIQUES

14 BROKEN

1 NOT SUITABLE

Page 40: High Performance Web Sites, With Ads: Don't let third parties make you slow

FRIENDLY IFRAME

Page 41: High Performance Web Sites, With Ads: Don't let third parties make you slow

Best Practices for Rich Media Ads in Asynchronous Ad Environments

http://www.iab.net/ajaxrichmedia

Page 42: High Performance Web Sites, With Ads: Don't let third parties make you slow

FRIENDLY IFRAME

Page 43: High Performance Web Sites, With Ads: Don't let third parties make you slow

IFRAMES OR JAVASCRIPT-May load in parallel-Possible to late-load-Browser sandbox-Fixed width/height-Adds overhead-No access to the DOM

-Full access to the DOM-Supports all types of ads-Blocks rendering/download-Not possible to late-load-Full access to the DOM

Page 44: High Performance Web Sites, With Ads: Don't let third parties make you slow

FRIENDLY IFRAME-May load in parallel-Possible to late-load-Browser sandbox-Full access to the DOM-Supports all types of ads

Page 45: High Performance Web Sites, With Ads: Don't let third parties make you slow

Create an iframe.

Set the source to a small static html page from the same domain.

1

Page 46: High Performance Web Sites, With Ads: Don't let third parties make you slow

Inside the iframe, set the JavaScript variable inDapIF = true to tell the ad it is loaded inside a friendly iframe.

2

Page 47: High Performance Web Sites, With Ads: Don't let third parties make you slow

Inside the iframe, create a script element with the ad url as the source.

Load the ad just like a normal JavaScript ad.

3

Page 48: High Performance Web Sites, With Ads: Don't let third parties make you slow

When the ad has finished loading, resize the iframe to fit the dimensions of the ad.

4

Page 49: High Performance Web Sites, With Ads: Don't let third parties make you slow

http://www.webpagetest.org/

Video of Aftonbladet.se loaded with and without Friendly Iframes

http://mittklipp.aftonbladet.se/app/viewMovie.action?id=36013

Page 50: High Performance Web Sites, With Ads: Don't let third parties make you slow

Minimize number of iframes?

Page 51: High Performance Web Sites, With Ads: Don't let third parties make you slow

”Using iframes is the best option today”

Page 52: High Performance Web Sites, With Ads: Don't let third parties make you slow

”Using iframes is the best option today”

Page 53: High Performance Web Sites, With Ads: Don't let third parties make you slow

”Using iframes is the best option today”

(not that it is a great solution)

Page 54: High Performance Web Sites, With Ads: Don't let third parties make you slow

”Using iframes is the best option today”

Page 55: High Performance Web Sites, With Ads: Don't let third parties make you slow

”Using iframes is the best option today”

(hopefully not forever)

Page 56: High Performance Web Sites, With Ads: Don't let third parties make you slow

TWEAKS

Page 57: High Performance Web Sites, With Ads: Don't let third parties make you slow

TWEAKSDon't load all ads at once. Use queues or delays.

Page 58: High Performance Web Sites, With Ads: Don't let third parties make you slow

TWEAKSDon't load all ads at once. Use queues or delays.

Set default sizes.

Page 59: High Performance Web Sites, With Ads: Don't let third parties make you slow

TWEAKSDon't load all ads at once. Use queues or delays.

Set default sizes.

Try not to block onload.

Page 60: High Performance Web Sites, With Ads: Don't let third parties make you slow

”BONUS” FEATURES

Page 61: High Performance Web Sites, With Ads: Don't let third parties make you slow

”BONUS” FEATURESAds may depend on other resources without blocking.

Page 62: High Performance Web Sites, With Ads: Don't let third parties make you slow

”BONUS” FEATURESAds may depend on other resources without blocking.

It is easy to reload ads.

Page 63: High Performance Web Sites, With Ads: Don't let third parties make you slow

THE FUTURE?

Page 64: High Performance Web Sites, With Ads: Don't let third parties make you slow

THE FUTURE?<frag>

Page 65: High Performance Web Sites, With Ads: Don't let third parties make you slow

THE FUTURE?<frag>

postMessage(...)

Page 66: High Performance Web Sites, With Ads: Don't let third parties make you slow

THE FUTURE?<frag>

postMessage(...)

ASWIFT?

Page 67: High Performance Web Sites, With Ads: Don't let third parties make you slow

THE FUTURE?<frag>

postMessage(...)

ASWIFT?

Something completely different

Page 68: High Performance Web Sites, With Ads: Don't let third parties make you slow

TEST AND MEASURE!

Page 69: High Performance Web Sites, With Ads: Don't let third parties make you slow

TEST AND MEASURE!

Tested through A/B testing during several months

Page 70: High Performance Web Sites, With Ads: Don't let third parties make you slow

FRONT PAGE

Page 71: High Performance Web Sites, With Ads: Don't let third parties make you slow

FRONT PAGE

VISITS/WEEK +7%

Page 72: High Performance Web Sites, With Ads: Don't let third parties make you slow

FRONT PAGE

VISITS/WEEK +7%PAGEVIEWS/VISIT +16%

Page 73: High Performance Web Sites, With Ads: Don't let third parties make you slow

LATEST NEWS

Page 74: High Performance Web Sites, With Ads: Don't let third parties make you slow

LATEST NEWS

+35%

Page 75: High Performance Web Sites, With Ads: Don't let third parties make you slow

AVERAGE PAGE LOAD TIME

-30%

Page 76: High Performance Web Sites, With Ads: Don't let third parties make you slow

DON'T TRUST THE EXPERTS

Page 77: High Performance Web Sites, With Ads: Don't let third parties make you slow

DON'T TRUST THE EXPERTS

(dont' trust me)

Page 78: High Performance Web Sites, With Ads: Don't let third parties make you slow

MEASURE EVERYTHING!

Page 79: High Performance Web Sites, With Ads: Don't let third parties make you slow

Tobias Jä[email protected]@jarlundhttp://blogg.aftonbladet.se/dev/