Advanced PWA. What you want to know when building mobile app for business

What I learned from building line of business mobile web apps

This article is intended to give you a broad technical overview of the main points you should consider when building a line of business PWA.

PWA is a great tech for building mobile app for front line workers or deployed employees

The first mover in PWA realm was the online press which realizes that people weren’t that eager to download an app from a store. Then e-commerce entered the field. Now, other business sectors are starting to see the advantage of building a PWA instead of developing a native app for 2 or 3 different platforms.

One case that appears to be great for PWA is mobile apps for front line workers and “not-in-front-of-a-desk” workers.
You can build a functional mobile app rapidly, with Web technologies only: HTML, CSS, Javascript.
And you do not need to go through an App Store registration process.

If you want to know more about why you should consider building a PWA, go read it.

You don’t need a Single Page Application.

You don’t need an over-bloated framework à la React, Angular, Vue…

Your user will be offline. Often. Deal with it.

The numerous reasons for being offline: a lot of parts of land even in wealthy countries have very poor Internet connectivity/ mobile network. Your user may be in the train, the metro, aboard a plane, in the middle of the sea, may not have enough battery to turn off airplane mode. Just no 3G/4G.

try{
    const response = await fetch(url, init)
    return await response.json();
} catch (fetchError){
    // see https://github.com/github/fetch/issues/201#issuecomment-308213104 for fetch fail
    console.log('You're offline, baby!')
    throw new Error('transmission_failed')
}

Use workbox.

Period. Just do it.

The library gives you lots of well thoughts methods. Let’s you organize your logic for routing, caching, …

Managing synchronization with a remote server is not always easy.

Background sync event is not always available (iOS) nor reliable (sometimes the sync event will not fire, or use up all 3 attempts but not reach the server).

// pseudo code
try { 
    <DB handler>::insert('myDB', myData);
} catch (UniqueConstraintViolationException $e) {
   // Return some meaningful state so that you can update syncState on your user’s side. 
    retun ['errorContent' => [ 
      'myObject' => [
        'uuid' => $myObject->uuid(),
        'msg' => 'Duplicate myObject'
      ]]];
}

You’ll need indexedDB to store your data.

Think carefully when creating an object Store

iOS exceptionalism

Be aware of some quirk by iOS Safari.

function blobToArrayBuffer(blob)
{
    return new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.addEventListener('loadend', (e) => {
            resolve(reader.result);
        });
    reader.addEventListener('error', reject);
    reader.readAsArrayBuffer(blob);
    });
}

Take extra good care of the UI

Other annoying bits

Mobile phone constructors have a nasty habit of not giving the user any way to manage how heavy should be the photo taken.
It’s not uncommon for a photo to be around 9-10Mo heavy.
Good luck uploading that beast on a flaky connection.
And resizing client-side is just… a computer-intensive task :/ See battery drainage above.

Now, go build some amazing PWAs!