RailsConf 2023 - Building an offline experience with a Rails-powered PWA by Alicia Rojas

Discover how to build an offline experience for your Rails application using a PWA, including strategies for caching, storage, and offline support with expert guidance from Alicia Rojas.

Key takeaways

To create an offline experience with a Rails-powered PWA, consider the following:

  • Build an application that can work both online and offline
  • Use service workers to handle requests and cache responses
  • Utilize Workbox strategies and IndexedDB for caching and storage
  • Implement a cache handler to set up a service worker
  • Use stimuli to populate templates with data and store records in IndexedDB
  • Configure service workers to intercept requests and retrieve responses from cache
  • Use BackgroundSync to perform CRUD actions while offline and sync with the server when connected
  • Consider using a manifest to configure the PWA’s behavior
  • Update views to include offline support using the Rails generate PwView command
  • Use a Stimulus controller to handle CRUD actions while offline
  • Implement a toggle to control online/offline mode
  • Ensure server-side rendering is used for better performance
  • Use a library like Workbox to simplify service worker setup and caching
  • Consider implementing offline support for forms and manually sync data
  • Use a tool like rails generate pillow install to create a PWA-ready view

Additional considerations:

  • Some browsers may not support BackgroundSync
  • Be mindful of browser compatibility when using PWAs
  • Use a simple, minimalistic approach to develop PWAs
  • Consider implementing an offline fallback for assets
  • Utilize the app manifest to configure PWA behavior
  • Cache responses to improve page performance
  • Store records in IndexedDB for offline use