55
Wednesday, March 21, 12

Faster mobile sites

Embed Size (px)

Citation preview

Page 1: Faster mobile sites

Wednesday, March 21, 12

Page 2: Faster mobile sites

Mobile

Faster Mobile SitesPresented by Matt Farina

Wednesday, March 21, 12

Page 3: Faster mobile sites

Hi, My name is Matt. You might know me as mfer. mattfarina.com@mattfarina

Wednesday, March 21, 12

Page 4: Faster mobile sites

http://www.slideshare.net/mattfarinahttp://speakerdeck.com/u/mattfarina

Download the slides...

Wednesday, March 21, 12

Page 5: Faster mobile sites

http://www.flickr.com/photos/robinhamman/337969896/Wednesday, March 21, 12

Page 6: Faster mobile sites

1. Why front end performance is important.

2. Where to look for performance issues.

3. Resources, tools, and stuff you can use.

4. Some actions you can take on your site.

Take Aways

Wednesday, March 21, 12

Page 7: Faster mobile sites

Before we talk about the fun and new stuff there’s are some things commonly talked about you should look into:

• CDN• Varnish• APC

Before We Get Started

• Memcache• Lots of other cool stuff

Wednesday, March 21, 12

Page 8: Faster mobile sites

Why is Front EndPerformance Important?

Wednesday, March 21, 12

Page 9: Faster mobile sites

http://www.stevesouders.com/blog/2012/02/10/the-performance-golden-rule/

13%

87%

Front End Back End

The HTTP Archive measurement of where time spent generating a page happens for

the top 50K sites.

Wednesday, March 21, 12

Page 10: Faster mobile sites

15%

85%

Front End Back End

3%

97%

Front End Back End

Desktop Mobile

http://www.readwriteweb.com/hack/2011/06/mobile-page-response.phpWednesday, March 21, 12

Page 11: Faster mobile sites

85% of mobile users expect sites to load at least as fast as using a desktop or laptop computer.

http://www.tealeaf.com/customer-experience-management/resource-center/register.php?doc=mobile-cemWednesday, March 21, 12

Page 12: Faster mobile sites

57% of online shoppers will wait three seconds or less before abandoning the site.

http://www.akamai.com/html/about/press/releases/2010/press_061410.htmlWednesday, March 21, 12

Page 13: Faster mobile sites

“Yahoo! reported that making pages just 400 milliseconds slower resulted in a traffic

drop of up to 9%.”

http://www.slideshare.net/stoyan/yslow-20-presentation

* Google, Amazon, and others have found similar results.

Wednesday, March 21, 12

Page 14: Faster mobile sites

SEOGoogle takes performance into

account in search engine rankings.

http://googlewebmastercentral.blogspot.com/2010/04/using-site-speed-in-web-search-ranking.htmlWednesday, March 21, 12

Page 15: Faster mobile sites

We aren’t just competing over user time and attention with other websites. We’re also competing against native apps.

Wednesday, March 21, 12

Page 16: Faster mobile sites

Part 1: Bandwidth

Wednesday, March 21, 12

Page 17: Faster mobile sites

http://www.flickr.com/photos/eliu500/5332240987/

4G will solve our problems, right?

Wednesday, March 21, 12

Page 18: Faster mobile sites

According to ITU (UN agency for information and communications technology) in 2011 we only had 45% of 3g or better coverage worldwide.

http://www.itu.int/ITU-D/ict/facts/2011/material/ICTFactsFigures2011.pdfWednesday, March 21, 12

Page 19: Faster mobile sites

“Research done at Google shows that an increase from 5Mbps to 10Mbps results in a disappointing 5% improvement in page load times. Or put slightly differently, a 10Mbps connection, on average uses only 16% of its capacity.”

http://www.igvita.com/2011/10/20/faster-web-vs-tcp-slow-start/Wednesday, March 21, 12

Page 20: Faster mobile sites

http://www.stevesouders.com/blog/2010/07/13/velocity-tcp-and-the-lower-bound-of-web-performance/

TCP connections aren’t great for small files (all your non-media assets are small

files). This is due to TCP slow start.

Wednesday, March 21, 12

Page 21: Faster mobile sites

If you pay for bandwidth and you can use less bandwidth to send the same functionality you have a savings at the same usage level.

Wednesday, March 21, 12

Page 22: Faster mobile sites

Minify Production JavaScript

• For example, minified drupal.js is 24% the size of the original.

• UglifyJS - a great minifierhttps://github.com/mishoo/UglifyJS

• Speedy Module - minified core JShttp://drupal.org/project/speedy

• Advanced CSS/JS Aggregation (D 6.x)http://drupal.org/project/advagg

Wednesday, March 21, 12

Page 23: Faster mobile sites

Quick Note On Legal Issues

• JavaScript downloaded to the browser is a form of distribution.

• The source (non-minified) must be linked to or publicly available. This could be a link in a comment.

• Preserve copyright / attribution comments.

Note: I’m not a lawyer and this is not legal advice.

Wednesday, March 21, 12

Page 24: Faster mobile sites

Contrib Challenge: If a project in contrib is using un-minified JavaScript for production file a bug. Remember, patches welcome.

Wednesday, March 21, 12

Page 25: Faster mobile sites

Original 41.3% Smaller

Use Lossless compressionon theme and module images.

Wednesday, March 21, 12

Page 26: Faster mobile sites

Compression Tools

ImageOptim - for mac and what I usehttp://imageoptim.pornel.net/

SmushIt - a web service owned by Yahoo!http://www.smushit.com/ysmush.it/

RIOT - Recommended to me but never usedhttp://luci.criosweb.ro/riot/

Wednesday, March 21, 12

Page 27: Faster mobile sites

Responsive Images

• Adaptive Imagehttp://drupal.org/project/adaptive_imageNote: Does not work with CDNs or reverse proxies.

• Responsive Imageshttp://drupal.org/project/responsive_imagesUses a special field formatter for images.

• Adaptive Image Styleshttp://drupal.org/project/aisRequires alterations to .htaccess and JS.

Wednesday, March 21, 12

Page 28: Faster mobile sites

Remove Image Styles Metadata

ImageMagick advanced module has an option to strip out metadata.

http://drupal.org/project/imagemagick

Wednesday, March 21, 12

Page 29: Faster mobile sites

Gzip Everything

When you send assets to the browser Gzip everything. Modern browsers (even IE 6)

support accepting Gzip compression.

• mod_deflate (for apache) • IIS (build in)• HttpGzipModule (nginx)

Wednesday, March 21, 12

Page 30: Faster mobile sites

Part 2: RTT and Connections

Wednesday, March 21, 12

Page 31: Faster mobile sites

6The number of parallel connections to a domain

across all tabs and windows in desktop browsers.

Wednesday, March 21, 12

Page 32: Faster mobile sites

iOS 5 Android 2.2 Android 2.3 Blackberry

6 4 6 5

• Android 2.2 has a 27.8% Android market share.• Android 2.3 has a 58.6% Android market share.• Android 4.x (ICS) has 1% Android market share.

Max Connections Per Host

Wednesday, March 21, 12

Page 33: Faster mobile sites

Browser Server

Round-trip Time (RTT)

“the length of time it takes for a signal to be sent plus the length of time it takes for an

acknowledgment of that signal to be received.”

https://en.wikipedia.org/wiki/Round-trip_delay_timeWednesday, March 21, 12

Page 34: Faster mobile sites

http://www.slideshare.net/guest22d4179/latency-trumps-all

Mobile phone network latency is 2-10x that of wired

connections.

Wednesday, March 21, 12

Page 35: Faster mobile sites

CSS Image Sprites

http://www.famfamfam.com/lab/icons/silk/Wednesday, March 21, 12

Page 36: Faster mobile sites

CSS Sprite ToolsGluehttp://glue.readthedocs.org/

Compasshttp://compass-style.org/

Sprite Cowhttp://www.spritecow.com/

SpritePadhttp://spritepad.wearekiss.com/

Wednesday, March 21, 12

Page 37: Faster mobile sites

Enable CSS and JavaScriptAggregation

In an unscientific random poll of DrupalCon attenders websites these were not enabled half the time. Not the first conference I’ve observed this at.

Wednesday, March 21, 12

Page 38: Faster mobile sites

“Adding an Expires header to your components with a date in the future makes them cacheable, reducing the load time of your pages. Certainly this should be done with images, but that's fairly typical. Go a step further and add it to scripts and stylesheets, too. This won't affect performance the first time users hit your page, but on subsequent page views it could reduce response times by 50% or more.”

http://stevesouders.com/hpws/rule-expires.phpWednesday, March 21, 12

Page 39: Faster mobile sites

What about caching and updating?

So, you’ve updated an image or a sprite and you want that to download but your

images are set to cache.

Solution: Use a custom name for each update. For example append a character you increment or a date. Or, use a query string.

This is what Google, Yahoo, and many others do.

Wednesday, March 21, 12

Page 40: Faster mobile sites

Warning: While desktop browsers generally have large caches, mobile browsers typically have a cache only several MB in size.

Wednesday, March 21, 12

Page 41: Faster mobile sites

Part 3: Mobile Devices

Wednesday, March 21, 12

Page 42: Faster mobile sites

10xJavaScript on mobile devices (high end

ones) takes about 10x as long to execute on mobile devices compared to desktop

computers.

Wednesday, March 21, 12

Page 43: Faster mobile sites

512MBThe amount of RAM in the iPhone 4s and

iPad 2. Mobile devices typically have 1GB or less of RAM. This helps extend battery life.

Wednesday, March 21, 12

Page 44: Faster mobile sites

What Can We Do About It?

Nothing Fancy with JavaScriptJS has less performance and memory to work with.

Simpler DOMA complicated DOM (divitis) uses more system resources. A simpler DOM has less objects in memory.

Mobile Optimized ImagesThey use less resources to render, manipulate, and keep in memory.

Wednesday, March 21, 12

Page 45: Faster mobile sites

Let’s Get A LittleAdvanced

Wednesday, March 21, 12

Page 46: Faster mobile sites

Alternatives To Caching

Local StorageGoogle, Bing, and others put assets in local storage.

Manifest AppcacheDesigned for html5 apps these can tell a browser to store assets for long periods.

If there isn’t much space to cache where else can we stick assets?

Wednesday, March 21, 12

Page 47: Faster mobile sites

What Else Can We Compress?

HTMLCompressorhttp://code.google.com/p/htmlcompressor/Minify HTML. In Drupal see hook_page_delivery_callback_alter and drupal_deliver_html_page.

mod_pagespeedApache module that automatically optimizes web pages and resources on them.

JavaScript, CSS, and images aren’t the only things that can be compressed.

Wednesday, March 21, 12

Page 48: Faster mobile sites

Delayed JavaScript Evaluation

All JavaScript included in a page needs to parsed and evaluated before

it becomes available.

jQuery on iPhone 4 takes 320ms to parse and evaluate. Lazy Evaluation waits until JS is needed to evaluate it.

Wednesday, March 21, 12

Page 49: Faster mobile sites

Update Your Linux Kernel

http://samsaffron.com/archive/2012/03/01/why-upgrading-your-linux-kernel-will-make-your-customers-much-happier

The Linux 3.3 kernel increases the TCP initial congestion window to 10. This can cut down the number of round trips to get data. Google and Microsoft already do this.

Wednesday, March 21, 12

Page 50: Faster mobile sites

Tools and Resources

Wednesday, March 21, 12

Page 51: Faster mobile sites

Tools and ResourcesPage Speedhttps://developers.google.com/pagespeed/Analyzes a website and generates suggestions. A website or browser plugin. Documentation details on suggestions.

Mobile Perf Bookmarklethttp://stevesouders.com/mobileperf/mobileperfbkm.phpTools to analyze on mobile and store data to analyze on desktop.

Performance Articleshttp://code.google.com/speed/articles/https://github.com/h5bp/mobile-boilerplate/wiki/Blog-and-ArticlesArticles about technologies related to performance.

Wednesday, March 21, 12

Page 52: Faster mobile sites

Chrome Developer Tools

Wednesday, March 21, 12

Page 53: Faster mobile sites

webpagetest.org

Wednesday, March 21, 12

Page 54: Faster mobile sites

Questions?

Twitter: @mattfarinaBlog: engineeredweb.com

http://www.slideshare.net/mattfarinahttp://speakerdeck.com/u/mattfarina

Wednesday, March 21, 12

Page 55: Faster mobile sites

What did you think?Locate this session on theDrupalCon Denver website

http://denver2012.drupal.org/program

Click the “Take the Survey” link.

Thank You!

Wednesday, March 21, 12