Preconnect, prefetch, prerender ...

Slides:



Advertisements
Similar presentations
Building Fast 3rd-Party Webapps O'Reilly Velocity Web Performance and Operations Conference 24 June Lessons.
Advertisements

©2013 AKAMAI | FASTER FORWARD TM It's all about Performance Measured and Perceived Performance on Desktop and Mobile Devices San Mateo Meetup, July 2013.
CHAPTER 15 WEBPAGE OPTIMIZATION. LEARNING OBJECTIVES How to test your web-page performance How browser and server interactions impact performance What.
Anderson Quach (Microsoft) Tony Gentilcore (Google)
Demystifying Page Load Performance with WProf Aruna Balasubramanian With Xiao (Sophia) Wang, Arvind Krishnamurthy, and David Wetherall University of Washington.
IBM WebSphere Portal © 2008 IBM Corporation 1 Deliver an Irresistible User Experience  Provides an interactive user experience  No programming needed,
Putting the Network to Work
Network. Add speed of light and speed in fiber Inspired by High Performance Browser Networking (Ilya Grigorik) Even Faster Web Sites (Steve Souders)
Mark Phillip markphillip.com 200s, 304s, Expires Headers, HTTP Compression, And You.
HTML 5 and Content Strategy for the Web By: Christina Fregosi ISC 496.
Building Highly Scalable Websites Karol Jarkovsky Sr. Solution Architect
THE BIG PICTURE. How does JavaScript interact with the browser?
JQUERY | INTRODUCTION. jQuery  Open source JavaScript library  Simplifies the interactions between  HTML document, or the Document Object Model (DOM),
MIS 425 Lecture 3 – HTML 5 and CSS Instructor: Martin Neuhard
Page Speed Bryan McQuade Richard Rabbat. Outline  What is Page Speed?  Inception of Page Speed  Cool features  Identify unused JavaScript and CSS.
AjaxScope & Doloto: Towards Optimizing Client-side Web 2.0 App Performance Ben Livshits Microsoft Research (joint work with Emre.
Don't Let Third Parties Slow You Down Arvind Jain, Michael Kleber Google.
Putting Performance Best Practices Together to Create the Perfect SPA Chris Love2Dev.com.
Web Technologies Lecture 7 Synchronous vs. asynchronous.
Unit 13 –JQuery Basics Instructor: Brent Presley.
30 Copyright © 2009, Oracle. All rights reserved. Using Oracle Business Intelligence Delivers.
WHAT'S THE DIFFERENCE BETWEEN A WEB APPLICATION STREAMING NETWORK AND A CDN? INSTART LOGIC.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
Site Speed: The Ultimate UX Feature… for SEO. A case study on how to increase search engine crawling and online conversion Jonathon Colman In-House SEO.
THE FUTURE IS HERE: APPLICATION- AWARE CACHING BY ASHOK ANAND.
WHAT'S NEW IN HTTP/2 BY DAWN PARZYCH. The front end optimization (FEO) movement was a result of the inefficiencies of HTTP/1.1. The availability of.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
What is Google Analytics?
What is jQuery?.
Digital Engineering & Mobile Solutions Performance Engineering Transformation Date: 03/11/2015 ©2013 Walgreen Co. All rights reserved.
Web Basics: HTML/CSS/JavaScript What are they?
Javascript and Dynamic Web Pages: Client Side Processing
Debugging Front-end Performance
Introduction to gathering and analyzing data via APIs Gus Cavanaugh
50 Performance Tricks to Make your HTML5 apps and sites Faster
Ad-blocker circumvention System
Web Languages What Is a Web Page?
ASP.NET Core Tag Helpers
Information Systems 337 Prof. Harry Plantinga Assessment.
Debugging IE Performance Issues xperf, ETW & NavigationTiming
Whether you decide to use hidden frames or XMLHttp, there are several things you'll need to consider when building an Ajax application. Expanding the role.
Web Programming– UFCFB Lecture 9
Building Native Mobile Apps with Angular 2.0 and NativeScript
Quick UDP Internet Connections
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
Tips for Website Speed Optimization
SPA Revolution with WebAssembly and Blazor Rainer Stropek | software
Introduction to JavaScript
Episerver Performance A-Z
Web Languages What Is a Web Page?
AMP.
Myth Busting: Top 5 Web App Myths
A second look at JavaScript
SPA Revolution with WebAssembly and Blazor Rainer Stropek | software
Morgan Kaufmann Publishers Memory Hierarchy: Cache Basics
Module P3 Practical: Building a webapp in nodejs and
Secure Web Programming
BUSINESS COMMUNICATION SKILLS PRESENTATION SKILLS OF THESIS & PROJECT
Teaching slides Chapter 6.
Document Structure & HTML
Introduction to JavaScript
Web Development 101 Workshop
HyperText Markup Language
Web Programming– UFCFB Lecture 9
Single Page Architecture (SPA)
Bootstrap Direct quote from source: bootstrap/
Meaning Matters Semantic Markup.
Web Programming and Design
Running C# in the browser
Yale Digital Conference 2019
Presentation transcript:

Preconnect, prefetch, prerender ... aka, building a web performance oracle in your application! Ilya Grigorik - @igrigorik igrigorik@google.com

Top 1M Alexa sites... Cable profile (5Mbps / 28 ms RTT) Main thread attribution in Blink Measured via Telemetry 69.5% of time blocked on network 6.6% of time blocked JavaScript 5.1% blocked on Layout 4.5% blocked on Paint ... No surprise here (hopefully) First page load is network bound First page load is latency bound blink-dev thread @igrigorik

Our pages consist of dozens of assets … (snip 30 requests) ... 52 requests 4+ seconds Huh? Primer on Web Performance (Chapter 10) @igrigorik

“Connection view” tells the story... 30 connections DNS lookups TCP handshakes … Blue: download time We’re not BW limited, we’re literally idling, waiting on the network to deliver resources. Speed, performance and human perception @igrigorik

Let’s build a smarter browser! We can hide some of the network latency through clever tricks.

The pre-* party... Preresolve Prefetch Prerender Preconnect Primer on Web Performance (Chapter 10) @igrigorik

Pre-resolve DNS names on browser startup... Scenario: when you load the browser first thing in the morning (or after restart), where do you usually head? Let’s pre-resolve all of the popular names! Chrome resolves top 10 destinations. Head to chrome://dns/ to see your list. High Performance Networking in Google Chrome @igrigorik

Preresolve is cute, but does it help much? How fast is your local DNS? Chrome knows the answer... chrome://histograms/DNS Good case: < 30 ms Average: 30-100 ms Ouch: 100 ms+ High Performance Networking in Google Chrome @igrigorik

Let’s predict where you’re heading next... If you type in “ama” what’s the likelihood you’re heading to Amazon? Chrome tracks the hit / miss count, and uses it to initiate DNS preresolve and TCP preconnect! High confidence hits may trigger a full prerender in a background tab. Head to chrome://predictors/ to see your list. High Performance Networking in Google Chrome @igrigorik

Hmm, pre-rendering you say? Tell me more... Head to chrome://net-internals/#prerender Try it yourself via prerender-test.appspot.com. High Performance Networking in Google Chrome @igrigorik

Instant Pages *is* Chrome Prerendering! High Performance Networking in Google Chrome @igrigorik

Could we optimize repeat visits further? Why, yes! Remember subresource hostnames + track stats on pre{connect, resolve} rates Use above information on future navigations to initiate appropriate actions... Check your own site: chrome://dns High Performance Networking in Google Chrome @igrigorik

Can we discover critical resources quicker? Yep... Chrome’s preloader delivers a ~20% speed improvement! Blocking resources block DOM construction... Preload scanner “looks ahead” in the HTML document to identify critical resources JavaScript, CSS, etc. Don’t hide your resources from the preload scanner! E.g. JS loaders, polyfills, etc. Chrome preloader @igrigorik

“We were using XHR to download CSS “We were using XHR to download CSS... When it came it our attention that XHRs are requested at low priority we decided to run an experiment to see its impact on G+ latency (vs using declarative markup like <link>). In SPDY capable browsers it (using <link>) resulted in a big latency improvement. In Chrome 27 we saw a 4x speedup at the median, and 5x at 25th percentile. In Firefox 21 we saw a 5x speedup at median, and 8x at 25th percentile.” Shubhie Panicker - G+ Front-end Team

In short, Chrome does a lot! but you can help it…

The browser is trying to predict and anticipate user activity, but you have the app-specific insights - leverage them! Pre-resolve DNS hostnames Mark critical subresources (don’t hide them!) Prefetch critical resources Prerender where applicable @igrigorik Speed is a feature (Chapter 1)

Embed “dns-prefetch” hints... <link rel="dns-prefetch" href="hostname_to_resolve.com"> <link rel="dns-prefetch" href="host2.com"> Embed prefetch hints in <head> to hint the browser to pre-resolve these names. Useful for critical resources later in the page Useful for resources behind a redirect host1.com/resource > 301 > host2.com/resouce dns-prefetch: host2.com (or even better, eliminate the redirect :)) High Performance Networking in Google Chrome @igrigorik

Embed “subresource” hints... <link rel="subresource" href="critical/app.js"> <link rel="subresource" href="critical/style.css"> Embed subresource hints in <head> to initiate immediate fetch for current page! Subresource hint identifies critical resources required for current page load. Place subresource hints as early as possible. In a way, this is a “manual preload scanner” strategy ... High Performance Networking in Google Chrome @igrigorik

Embed “prefetch” hints... <link rel="prefetch" href="checkout.html"> <link rel="prefetch" href="other-styles.css"> Embed prefetch hints in <head> to initiate deferred fetch for later navigation. Prefetch hint identifies resources that may be needed in future navigation. Prefetch hints have lowest possible priority. Prefetch hints are content agnostic: fetch asset, place in cache. You do have cache headers enabled, right? Right? High Performance Networking in Google Chrome @igrigorik

Embed “prerender” hints... <link rel="prerender" href="checkout.html"> Embed prerender hints in <head> to initiate background prerender of entire page! The page is fetch, and all of its assets! Use Page Visibility API to defer JS actions until page is visible. Analytics beacons (GA does this already), custom code, etc. Only “safe” pages can be prerendered (aka, GET). Prerendering is resource heavy - use with caution. High Performance Networking in Google Chrome @igrigorik

Predict, measure, optimize… iterate. You can inject each of the hints when the page is generated You know the structure of the page / application, use it... Run offline log analysis (e.g. step_a.html > step_b.html) You can inject hints “at runtime” based on user interactions! Via the magic of JavaScript, simply add the appropriate link tag: var hint = document.createElement("link") hint.setAttribute("rel", "prerender") hint.setAttribute("href", "next-page.html") document.getElementsByTagName("head")[0].appendChild(hint) P.S. If the hint is no longer relevant, reverse works also.. nuke it from the DOM!

TL;DR <link rel="dns-prefetch" href="hostname_to_resolve.com"> Pre-resolve DNS hostnames for assets later in the page! (Most browsers) <link rel="subresource" href="/javascript/myapp.js"> Initiate early resource fetch for current navigation (Chrome only) <link rel="prefetch" href="/images/big.jpeg"> Prefetch asset for a future navigation, place in cache… (Most browsers) <link rel="prerender" href="//example.org/next_page.html"> Prerender page in background tab for future navigation Twitter igrigorik Email igrigorik@google.com Web igvita.com Slides @ bit.ly/1bUFCsI Checkout Steve’s prebrowsing slides!