Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Progressive Web App Performance

Progressive Web App Performance

An exploration of the use of caching methods to improve absolute and perceived performance on the mobile web.

Danielle Brook-Roberge

February 15, 2017
Tweet

More Decks by Danielle Brook-Roberge

Other Decks in Programming

Transcript

  1. Progressive Web Apps » A progressive web app (PWA) is

    a web application that aims to provide a native-like experience through progressive enhancement. » This concept has been pushed strongly by Google; they have added a number of features to Chrome specifically for PWAs. » Nevertheless, PWA designs can provide improved experiences on all devices, not just ones running Chrome.
  2. PWAs at Mobify » At Mobify, we have developed a

    number of progressive web apps for retailers using React and Redux. » We have created a toolkit to develop these apps quickly. » This toolkit reflects our current best practices, including for performance.
  3. Redux Data Storage » We store all of the data

    in our apps in a Redux store. » This includes both UI state, and data received from the backend. » With the right store schema, we can make maximum use of the backend data to provide a smooth, high-performance experience for the user. » These techniques do not depend on new web features, so they work on all platforms.
  4. Keep All Available Data » We have several classes of

    page that are all based on the same template, such as category pages » For these classes, we make sure that the contents of all pages are kept in the store, allowing very fast transitions between already-loaded pages.
  5. Store Generalized Data Centrally » When loading one page, some

    of the data fetched from the backend may be relevant for other pages as well. » For example, a category page may include titles of products, prices, and product images » If we store this information where the relevant product page can find it, then when navigating to the product, we already have basic information available.
  6. Service Workers » The ServiceWorker API allows a secure web

    app to register a Javascript program to control caching. » The service worker code has full control over HTTP requests made by pages in its scope. » It can satisfy these requests with actual network requests, or with generated or cached data that does not require a network roundtrip. » Service workers are implemented on most browsers and platforms, but not iOS or Safari.
  7. Reload Performance and You » With today's mobile devices, page

    reloads are much more common than they would be in the past, due to browsers' aggressive reclamation of memory and other resources. » Service worker caching can dramatically speed up page reloads, preventing network round-trips for some or all of the necessary assets. » To do this, we must judiciously choose our caching strategy to avoid unnecessary delays.
  8. sw-toolbox » Google has released a helper library for service

    worker caching » It provides a mechanism for associating URL patterns with caching strategies, and includes implementations of most basic caching Strategies » It also handles cache expiration, which is not handled automatically by the worker cache API
  9. Network-First » With a network-first strategy, the request is sent

    to the server, falling back to a cached response if the server is unreachable. » This strategy is the most cautious in ensuring the data is up to date, but requires a network roundtrip to complete for every resource before it is returned to the page.
  10. Cache-First » With a cache-first strategy, the cached asset is

    returned if it is available, only fetching from the server if it is not present in the cache. » This strategy is the fastest, but ignores all changes to the resource after it is first fetched. This is useful for cache- broken assets which can be assumed to never change.
  11. Fastest » With a fastest strategy, whichever of the cache

    and the network that responds faster will be used. The network request will always be made and the result will be cached if it is successful. » This strategy will, effectively, always return the cached value immediately if it exists, but update it in the background from the network
  12. Caching Strategies at Mobify » The service worker we currently

    use for our PWA builds uses all three of these strategies. » Cache-first is used for the webpack bundle assets and web fonts, which are all cache-broken » Fastest is used for images, keeping the last 15 images in the cache. » Network-first is used for all other resources.