Slide 1

Slide 1 text

Freaky Fast Delivery @BradBroulik | BradBroulik@gmail.com BradBroulik.blogspot.com

Slide 2

Slide 2 text

2 Poor Performance causes Stress http://www.webperformancetoday.com/2013/12/11/slower-web-pages-user-frustration/

Slide 3

Slide 3 text

3 Responsive Performance http://www.guypo.com/mobile/performance-implications-of-responsive-design-book-contribution/ http://blog.kissmetrics.com/loading-time/?wide=1 •Fewer HTTP requests. •Compress images (ImageOptim, PNG Crush). •Load visible content first or defer everything else. •Minify and merge JavaScript assets. •Prefer sprites or use Data URI for images. •Use CDNs when available. •Avoid geolocation on initial home screen. •Dedicate time for performance testing. •Web storage. •Networks and devices will eventually get faster. Performance tips “86% of sites listed on mediaqueri.es weighed roughly the same when loaded in the smallest window, compared to the largest one. In other words, the mobile site is still downloading the full website content.” -- Guy Podjarny

Slide 4

Slide 4 text

4 HTML CSS CSS JS JS Blocking CAUTION: CSS and JavaScript assets loaded in the head via and tags are blocking requests - they block the document from appearing until all assets are loaded. HTML Traditional Request Loading Cell tower DNS Server

Slide 5

Slide 5 text

5 Full CSS Lazy load non- critical assets HTML Responsible Performance Critical CSS Async JS Loader HTML Critical CSS Async JS Loader TIP: Deliver the critical CSS and JavaScript inline on initial page request and lazy load non-critical assets for optimal page load performance! • Enhance.JS • Critical CSS Bookmarklet • Grunt-CriticalCSS Critical CSS - The minimal CSS necessary to render a particular page. It’s a subset of the full CSS. HTML contains all the assets to render the initial page in a single request. Asynchronously load the non- critical assets after initial page load via enhance.js Cell tower DNS Server Full JS Full Fonts Goal: one-second perceived load time

Slide 6

Slide 6 text

6 Traditional vs Enhanced

Slide 7

Slide 7 text

7 Download and Hide #1 reason for bloat Desktop Article hidden in DOM TIP: Instead of hiding unnecessary markup in the DOM with display:none don’t even download it!

Slide 8

Slide 8 text

8 http://filamentgroup.com/lab/ajax_includes_modular_content/ NOTE: Entertainment articles are lazy loaded after page load NOTE: Technology articles are only loaded when min-width: 30em Lazy Loading

Slide 9

Slide 9 text

9 Download and Shrink #2 reason for bloat Large desktop image scaled down TIP: Instead of shrinking large image assets within small viewports, download the optimized smaller images!

Slide 10

Slide 10 text

10 Responsive Images http://responsiveimages.org

Slide 11

Slide 11 text

11 Scott Jehl: https://github.com/scottjehl/picturefill TIP: Picturefill is a responsive image polyfill for , srcset, sizes, and more that you may begin using today!

Slide 12

Slide 12 text

12 Use Case: device-pixel-ratio pic srcset: set of sources with w (width) or x (resolution) descriptors. 1x (150 x 150 px) 2x (300 x 300 px) 3x (450 x 450 px) CAUTION: srcset can be defined with w (width) or x (resolution) descriptors but not both. They do not mix. src: fallback ing if srcset is not supported. http://www.smashingmagazine.com/2014/05/14/responsive-images-done-right-guide-picture-srcset/

Slide 13

Slide 13 text

13 “pic" Use Case: fluid image Variable Known by browser when it’s loading the page? viewport dimensions yes image size relative to viewport yes via sizes screen density yes source files’ dimensions yes via srcset NOTE: We tell the browser the rendered size of our images and the browser picks the preferred image for it’s container. Very Cool! sizes: can be absolute (px or em), relative to the viewport (vw), or dynamic calc(.333 * 100vw -12em) http://ericportis.com/posts/2014/srcset-sizes/

Slide 14

Slide 14 text

14 pic Use Case: variable-sized image sizes=“[media query] [length], [media query] [length], [length] If no media query it is the default size

Slide 15

Slide 15 text

15 Art direction This technique allows us to use smaller images that appear larger on smaller viewports by cropping the subject of the photo.

Slide 16

Slide 16 text

16 pic TIP: Prefer picture element for art-directed and type- switching use cases. Use Case: art direction Load art-directed (cropped) images when below 36ems http://scottjehl.github.io/picturefill/#ie9

Slide 17

Slide 17 text

17 “logo" If the browser doesn’t find a compatible source type it will fallback to the img Use Case: type-switching

Slide 18

Slide 18 text

18 Compress Images http://imageoptim.com/ Simply drag-n-drop images and they’ll be automatically optimized in-place.

Slide 19

Slide 19 text

19 Chrome developer tools Compress with GZip TIP: Verify you’re using gzip in Chrome developer tools. Click “Network” tab and do a refresh on the page. Click on the top document entry in the list and select “Headers” on the right side. If you find “Content-Encoding: gzip” in the list, then the page is gzip-compressed.

Slide 20

Slide 20 text

20 HTTP/2 SPDY & HTTP2 Overview Header Compression Server Push Multiplexing http://caniuse.com/#feat=http2

Slide 21

Slide 21 text

21 Responsible Fonts TIP: Load fonts asynchronously and progressively with Google’s Web Font Loader! https://github.com/typekit/webfontloader 1. Show a fallback font while the custom fonts asynchronously load. Use a fallback font that appears similar to the custom font to avoid a Flash Of Unstyled Text (FOUT). 2. The layout will progressively enhance to the custom fonts after they are loaded. Console logs show font loading events

Slide 22

Slide 22 text

22 Asynchronous JavaScript https://developers.google.com/speed/docs/insights/BlockingJS#deferJS http://www.growingwiththeweb.com/2014/02/async-vs-defer-attributes.html <script async> <script defer>

Slide 23

Slide 23 text

23 Browser Caching https://developers.google.com/speed/docs/insights/LeverageBrowserCaching Cache response for 120 seconds ETag token uniquely identifies the response (data) Request #1 Request #2 The response hasn’t change and as a result the ETags match. Response is 304 (no data)

Slide 24

Slide 24 text

24 Browser Caching https://developers.google.com/speed/docs/insights/LeverageBrowserCaching Define Optimal Cache-Control Policy

Slide 25

Slide 25 text

25 Web Storage Examples: •bonus/html5/webstorage.html localStorage // Store localStorage.setItem("lastName", "Peterson"); // Retrieve $("#lastName").html(localStorage.getItem("lastName")); // Remove localStorage.removeItem("lastName"); 25 http://caniuse.com/#search=localstorage http://en.wikipedia.org/wiki/Web_storage sessionStorage

Slide 26

Slide 26 text

26 PageSpeed Insights https://developers.google.com/speed/pagespeed/insights/ TIP: Analyze your site and get recommendations for performance improvements.

Slide 27

Slide 27 text

27 Perceived Performance http://www.webpagetest.org/ TIP: A one-second page load is the ultimate goal. Or verify your site is 20% faster than the competition. Speed Index is the ideal measurement for perceived performance. Shoot for a Speed Index of 1000. The average is 4493.

Slide 28

Slide 28 text

28 Perceived Performance https://sites.google.com/a/webpagetest.org/docs/using-webpagetest/scripting logger off logger on TIP: A one-second page load is the standard goal. Verify your site is 20% faster than the competition.

Slide 29

Slide 29 text

29 Performance Budget http://timkadlec.com/2014/05/performance-budgeting-with-grunt/ TIP: Setup an automated performance budget test to validate your build is within a certain SpeedIndex or render time. Verify the SpeedIndex (perceived performance) is within our goal of 1.2 seconds Verify the site starts rendering with the goal of one-second

Slide 30

Slide 30 text

30 Chrome developer tools Safari Web Inspector Browser Testing Tools http://devtoolsecrets.com/ http://webperformance.io/devtools-filmstrip

Slide 31

Slide 31 text

31 Thank You! @BradBroulik BradBroulik.blogspot.com BradBroulik@gmail.com