Adaptive Loading: Do not just respond based on screen size, adapt based on actual device hardware.
Any user can have a slow experience. In a world with widely varying device capabilities, a "one-size" fits all experience may not always work. Sites that delight users on high-end devices can be unusable on low-end ones, particularly on median mobile and desktop hardware and in emerging markets. What if we could adapt how we deliver pages to better cater for our user's constraints? π€
In our Chrome Dev Summit talk, Facebook's Nate Schloss and I talk about Adaptive Loading - this pattern ...
Delivers a fast core experience to all users (including low-end devices)
Progressively adds high-end-only features, if a user's network and hardware can handle it.
This allows users to get an experience best suited to their constraints.
The use-cases adaptive loading unlocks include:
Serving low-quality images & videos on slow networks
Loading non-critical JavaScript for interactivity only on fast CPUs
Throttling the frame-rate of Animations on low-end devices
Avoiding computationally heavy operations on low-end devices
Block 3rd-party scripts on slower devices
There are a number of signals we can use for Adaptive Loading, including:
Memory - for reducing memory consumption on low-end devices (via navigator.deviceMemory)
CPU core count - for limiting costly JavaScript execution and reducing CPU intensive logic when a device can't handle it well (via navigator.hardwareConcurrency). This is because JavaScript execution is CPU bound.
In our talk, we cover real-world examples of these ideas being used in sites such as Facebook, eBay, Tinder and others. Check out 24mins in where Nate walks through how Facebook uses some of these ideas in production, via device grouping:
We also released a new (experimental) set of React Hooks & Utilities for adding adaptive-loading techniques to your React apps.
It can be used to add patterns for adaptive resource loading, data-fetching, code-splitting and capability toggling.
Objective
Make it easier to target low-end devices while progressively adding high-end-only features on top. Using these hooks and utilities can help you give users a great experience best suited to their device and network constraints.
Installation
npm i react-adaptive-hooks --save or yarn add react-adaptive-hooks
Usage
You can import the hooks you wish to use as follows:
In the future, we hope to see more examples of infrastructure that can automatically deliver the most optimal bundles of code based on a user's network & device constraints. Between Client Hints and the client-side APIs used above, the building blocks to build something compelling in this space may already exist :)
We hope you'll find Adaptive Loading an interesting addition to your Progressive Enhancement toolbox. Check out our talk to learn more :)