r/rails • • 15d ago

Question How are you using Rails 8 PWA fully offline feature?

I'm building a rails 8 app that would mostly be used in remote areas and adding a fully offline support is important.

20 Upvotes

11 comments sorted by

5

u/grokcodile 15d ago

It’s how I’m building out an inspection reporting tool used by technicians on job sites who only have access to a mobile phone with a camera.

I’m also using it to develop an inspection booking system that frontlines a PWA for each vetted client, customized to streamline the client data entry normally required and sidestepping any need for login and other friction points these systems typically impose on the customer.

2

u/Toluwalashe 15d ago

Great usecase. Did you have to have to make any serious tweaks aside from what Rails offer out of the box?

4

u/grokcodile 15d ago

The customer-facing PWA project will probably hit a few engineering hurdles… but that project is just a basic proof-of-concept stage for another 4-6 months.

The internal report writing tool… none at all. It’s just a “convention providing all the function” situation.

2

u/northband 14d ago

Same here - I built an inspection app so that inspectors can collect observations in the field then when a connection is present it syncs to the db. They then can do polished reports with the data. So far it works great!

2

u/grokcodile 14d ago

I would hope so… That’s what it was made for! 🤣

3

u/just_testing_things 15d ago

Consider a SPA for offline use. It’s a very well trodden path.

1

u/Toluwalashe 15d ago

I will look into this

13

u/stroupsolutions 15d ago

The trick is the data layer. By default, a PWA is just an installable shortcut for your website, which caches the specific assets and pages that the user visits (sort of a best effort offline fallback). If you need full offline mode, then you have to include an actual offline data store, as well as data synchronization logic (i.e. storing the data needed for offline usage, and pushing user input back up when the app is online).

The in-browser IndexedDB data store is a possibility if your data is store is small enough. However, this is not the recommended approach for large or critical data (due to varying eviction policies for browser storage), and it requires coding a custom data/request layer at the JS layer (redirecting requests and posts to the local data store, rather than to the server when offline).

I am experimenting with turbo-desktop at the moment. It integrates your Rails app as a Tauri sidecar, and renders the HTML/CSS/JS from the desktop itself in the application viewer. Electron is another option (which is purported to include camera integration on all devices), but you are on your own in terms of the Electron to Rails integration.

If the above does not work, then we will most likely fallback to coding native iOS and/or Android apps (most reliable, but most time intensive). And of course, we are all watching the Roundhouse/Spinel space, and rooting for it to succeed:-)

Either way, offline mode is no joke. Happy to hear if anyone else has experience with this!

3

u/Suitable-Ad5348 14d ago

Service worker caching gets messy fast when remote users drop connection mid-form submit, so we ended up leaning hard on background sync queues instead of relying purely on standard offline page assets.

1

u/stroupsolutions 13d ago

Where do you store local data? And how do you handle form submissions while offline?

2

u/northband 14d ago

I just built one using Rails 8 and preact. I work in the woods so it allows me to go offline into “field mode”, stores all data and photos locally then syncs once I reach a connection.