Progressive Web Apps with React

Book description

Enhance the performance of your applications by using React and adding the Progressive web app capability to it

About This Book

  • Bring the best of mobile sites and native apps to your users with progressive web applications
  • Create fast, reliable, and engaging PWAs with React and Firebase
  • Create high-performance applications even with low connection speeds by leveraging modern web technologies

Who This Book Is For

This book is for Javascript Developers who want to develop high performance Web User Interfaces. This book requires basic knowledge of HTML, CSS and JavaScript.

What You Will Learn

  • Set up Webpack configuration, as well as get the development server running
  • Learn basic Firebase configuration and deployment
  • Create routes, manage multiple components, and learn how to use React Router v4 to manage the flow of data
  • Use React life cycle methods to load data
  • Add a service worker to the app and learn how it works
  • Use a service worker to send Push Notifications
  • Configure Webpack to split up the JavaScript bundle and lazy load component files
  • Learn how to use the web Cache API to use your app offline
  • Audit PWAs with Google's Lighthouse tool

In Detail

For years, the speed and power of web apps has lagged behind native applications. Progressive Web Apps (PWAs) aim to solve this by bridging the gap between the web apps and native apps, delivering a host of exciting features. Simultaneously, React is fast becoming the go-to solution for building modern web UIs, combining ease of development with performance and capability. Using React alongside PWA technology will make it easy for you to build a fast, beautiful, and functional web app.

After an introduction and brief overview of the goals of PWAs, the book moves on to setting up the application structure. From there, it covers the Webpack build process and the process of creating React components. You'll learn how to set up the backend database and authentication solution to communicate with Firebase and how to work with React Router. Next, you will create and configure your web app manifest, making your PWA installable on mobile devices. Then you'll get introduced to service workers and see how they work as we configure the app to send push notifications using Firebase Cloud Messaging. We'll also explore the App Shell pattern, a key concept in PWAs and look at its advantages regarding efficient performance. Finally, you'll learn how to add offline capabilities to the app with caching and confirm your progress by auditing your PWA with Lighthouse. Also, you'll discover helper libraries and shortcuts that will help you save time and understand the future of PWA development.

Style and approach

This is a step-by-step book, wherein, you will use the React framework to create a complete progressive web app.

Table of contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Creating Our App Structure
    1. Setting the scene
      1. The problem
      2. The other problem
    2. Beginning work
      1. Why Progressive Web Apps?
      2. Why React?
        1. A rose by any other name
    3. User stories
    4. Application challenges
      1. Instant loading
      2. Push notifications
      3. Offline access
      4. Mobile-first design
      5. Progressive enhancement
    5. Let's get going
      1. Our app skeleton
      2. CSS and assets
      3. Meta tags and favicons
    6. What is npm?
    7. Node setup
    8. The dark side of npm
    9. Project initiation
      1. Installing React
      2. Using React
    10. Welcome to ReactDOM
    11. Summary
  3. Getting Started with Webpack
    1. Our project structure
    2. Welcome to Webpack
      1. Bundling files
      2. Moving our React
      3. Shortcuts
      4. Our Dev server
    3. Webpack loaders
      1. Our first ES6
      2. Splitting up our app
    4. Hot reloading
      1. Building for production
        1. Creating a custom script
        2. Making an asset manifest
    5. Summary
  4. Our App's Login Page
    1. What is a React component?
      1. Controversies and Separation of Concerns
    2. Class components versus functional components
    3. Our second component
    4. State in React
    5. Reusing components
    6. Summary
  5. Easy Backend Setup With Firebase
    1. What is Firebase?
      1. Firebase gotchas
    2. Setting up
      1. Hiding our API key
      2. Deploying Firebase
    3. Authentication with Firebase
      1. What is a promise?
      2. Back to authentication
      3. Code cleanup
      4. Signing up
    4. Saving our user
      1. Event listeners
      2. Lifecycle methods
    5. Summary
  6. Routing with React
    1. The plan
    2. Pages on pages
      1. The React Router difference
    3. Our ChatContainer
      1. Installing React Router
      2. Our BrowserRouter
    4. Our first two Routes
    5. Redirecting on login
    6. Logging out
      1. Detour - higher order components
    7. Our third Route
    8. Summary
  7. Completing Our App
    1. User stories progress
    2. ChatContainer skeleton
    3. Managing data flow
    4. Creating a message
      1. Sending a message to Firebase
        1. Our message data
    5. Loading data from Firebase
    6. Displaying our messages
    7. Message display improvements
      1. Multiple users
      2. Batching user messages
      3. Scrolling down
      4. React refs
      5. Loading indicator
    8. The Profile page
    9. Summary
  8. Adding a Service Worker
    1. What is a service worker?
    2. The service worker life cycle
    3. Registering our first service worker
      1. Checking for browser support
      2. Listening for the page load
      3. Registering the service worker
      4. Logging out the result
    4. Experiencing the service worker life cycle
    5. Adding Firebase to our service worker
      1. Naming our service worker
    6. Summary
  9. Using a Service Worker to Send Push Notifications
    1. Requesting permission
    2. Tracking tokens
    3. Attaching a user to the token
      1. Changing the user inside NotificationResource
      2. Creating a new token
      3. Updating an existing token
    4. Sending push notifications
      1. Writing our Cloud function
      2. Sending to the tokens
      3. Testing our push notifications
      4. Debugging push notifications
        1. Checking the Cloud Functions logs
        2. Checking the Service Worker
        3. Checking the tokens
    5. Summary
  10. Making Our App Installable with a Manifest
    1. What is an app manifest?
      1. Browser support
    2. Making our app installable - Android
      1. Manifest properties
        1. Other properties
      2. Linking our manifest
    3. Making our app installable - iOS
    4. App install banners and you
      1. Delaying the app install banner
      2. Listening for the event
    5. Summary
  11. The App Shell
    1. What is progressive enhancement?
    2. The RAIL model
      1. Load
      2. Idle
      3. Animation
      4. Response
      5. Timeline
    3. Measuring using the timeline
      1. The Summary tab
      2. Network requests
      3. Waterfall
      4. Screenshots
    4. PageSpeed Insights
    5. The app shell pattern
      1. Moving shell HTML out of React
      2. Moving CSS out of React
      3. Moving the loading indicator
    6. Summary
  12. Chunking JavaScript to Optimize Performance with Webpack
    1. The PRPL pattern
      1. Push
      2. Render
      3. Pre-cache
      4. Lazy-load
    2. What is code splitting?
      1. Webpack configuration
        1. Babel stage 1
      2. Conditional imports
    3. Higher-order components
      1. AsyncComponent
    4. Route splitting
    5. Lazy loading
    6. Summary
  13. Ready to Cache
    1. What is caching?
      1. The importance of caching
    2. The Cache API
      1. Methods
      2. The asset manifest
      3. Setting up our cache
      4. The install event
        1. Opening up the cache
        2. Fetching the asset manifest
        3. Parsing the JSON
        4. Adding the relevant URLs to the cache
      5. The fetch event
      6. The activate event
        1. Grab the list of cache names
        2. Loop over them
    3. Testing our cache
    4. Summary
  14. Auditing Our App
    1. What is Lighthouse?
    2. The criteria
    3. The Audits tab
    4. Our first audit
    5. Evaluating the readout
    6. Using the Lighthouse CLI
      1. Serving our build folder
      2. Using Lighthouse to assess the served page
      3. Logging the results
    7. Summary
  15. Conclusion and Next Steps
    1. Next steps
    2. Learning resources
    3. Case studies
      1. Building the Google I/O 2016 Progressive Web App
      2. AliExpress case study
      3. eXtra Electronics case study
      4. Jumia case study
      5. Konga case study
      6. SUUMO case study
    4. Example applications
      1. PWA.rocks
      2. Flipboard
      3. React Hacker News
      4. Notes
      5. Twitter
      6. 2048 Puzzle
    5. Articles to read
      1. Native apps are doomed
      2. A BIG list of Progressive Web App tips & tricks
      3. Testing service workers
      4. Twitter Lite and High Performance React Progressive Web Apps at Scale
      5. Why are App Install Banners Still a thing?
      6. A Progressive Web Application with Vue JS
      7. Transforming an existing Angular application into a Progressive Web App
      8. Progressing the Web
      9. Designed Degradations - UX Patterns for Hostile Environments
      10. Instant Loading Web Apps With An Application Shell Architecture
      11. Trick users into thinking your site's faster than it is
      12. Apple’s refusal to support Progressive Web Apps is a detriment to the future of the web
    6. Tools
      1. Workbox
      2. Sw-precache
      3. Sw-toolbox
      4. Offline-plugin
      5. Manifest-json
      6. Serviceworker-rails
      7. Sw-offline-google-analytics
      8. Dynamic Service Workers (DSW)
      9. UpUp
      10. Generator-pwa
      11. Progressive-webapp-config
    7. Stretch goals
      1. Switch to Preact
      2. Show online status
      3. Show when typing
      4. Include file upload
      5. Create chat rooms
      6. Interactive without React
      7. Building your own backend
    8. Closing words
    9. Summary

Product information

  • Title: Progressive Web Apps with React
  • Author(s): Scott Domes
  • Release date: October 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781788297554