Progressive Web Apps: an alternative to native apps
Developers see Progressive Web Apps as an excellent alternative to native apps because they offer some appealing advantages.

Editorial translation by Impulso.
If you use your smartphone more than your laptop, you know how annoying it is to install more and more bulky apps and regularly burn through your data allowance on updates.
Modern browsers have been working to support PWAs (progressive web apps), web applications that behave like regular apps without requiring installation on the user's device.
From a developer's perspective, PWAs are an excellent alternative to native apps, with some very appealing advantages:
- Eliminate the need to install apps on the device;
- Enable automatic updates without requiring the user to do anything;
- Take advantage of the browser cache to reduce the number of requests to the server;
- Access device features such as GPS, the camera, and the accelerometer, since the browser already has those permissions;
- Offer a user experience that is identical or very similar to that of native apps;
- Work with all major operating systems;
- Can also be installed on a desktop just like a native app;
- Cut development time dramatically.
Who's using them?
There are lots of possibilities being explored with this approach. Major players such as AliExpress, Uber, Instagram, Twitter, AirBnB, Spotify, and many others have already moved their web interfaces to progressive web apps.
Uber, for example, lets you request rides without installing a native app. It has fewer features than the official app, but you can still track your ride via GPS, make microtransactions, receive push notifications, and manage your account.
I like it. How do I get started?
Before you dive into implementation, it's important to understand what makes a web app progressive.
Reliable: The app needs to be highly available, accessible over slow connections (2G, for example), and use HTTPS.
Easy to use: Navigation should be simple and interactive. A great example is using transitions between screens so users don't have to scroll.
Responsive: The app should offer the same experience on any device.
“A progressive app should be like a liquid: it adapts to any container it's poured into.”
Mahesh Haldar, Bits & Pieces
Installable: It should give users the same experience as a native app. That means users should be able to install it on their device's home screen.
Engaging: The app should encourage users to engage with it. PWAs can send push notifications, access device features, work offline, and so on. Use these capabilities to encourage engagement.
Offline: A PWA must use the cache so users can interact with it without staying connected or waiting for the server to respond.
How do I make my web app work offline?
The secret behind PWAs is service workers: browser features that act as a proxy between the server and the client.
Here's how it works:
- The user opens your app for the first time. The client fetches the files from the server.
- The service worker intercepts the request and checks whether those files should be cached. If they should, it checks whether there's already a cached copy of the files.
- If there is, it returns the cached copy to the client.
- If there isn't, it fetches the files from the server, caches the result, and returns it to the client.
It's essential to cache all frontend assets through the service worker so users can navigate the app offline without having to send requests to the server.
Ready to code? First, we need to create the file that registers the service worker and checks whether the browser supports it:
Image unavailable in the original source.
main.js
On line 1, we start registering `serviceWorker` if it's available on the global `navigator` object, which exposes browser capabilities.
Next, on lines 2 and 3, we tell the browser to register the service worker configured in `service-worker.js`.
If the browser can find, interpret, and register the worker, we log a success message to the console (lines 4–6). Otherwise, we log a warning (lines 7–8).
Image unavailable in the original source.
service-worker.js
On line 1, we list the files whose requests the service worker caches after intercepting them. Each path must be relative to the app's root. For example, if we want to cache www.impulso.network/assets/logo.svg, we add this to the array: `assets/logo.svg`
Next, on line 5, we name our cache. If we make a major change, it's important to change this name too.
When the browser runs the service worker for the first time, it fires the install event. At this stage (lines 7–17), we open the cache and add the files listed in `files` to it. Then the browser fires the activate event, which we'll handle later.
Next comes the fetch event, where the magic happens. On lines 19–25, we intercept the request to the server and check whether the URL is cached by the service worker. If so, we return the cached version. Otherwise, we complete the request and return the response to the client.
Finally, if this file changes at all, the activate event fires. According to the official Chrome documentation, if even one byte in the service worker file differs from the browser's copy, the browser treats it as new. We handle this event on lines 27–39, where we delete any file removed from the `files` variable from the cache.
This way, we make the app work offline by caching the files we used to fetch from the server on every request.
How does the user install it?
The app must let users install it on their home screen. We need to give the browser information about our app, and we do that through the manifest.json file.
Image unavailable in the original source.
manifest.json
In this file, we specify the app's icon, start URL, colors, and name. You can find more options here.
This way, the browser will suggest that returning users install the PWA instead of the native app.
Image unavailable in the original source.
Finally, to make everything work, we need to reference our manifest and registration script in index.html.
Image unavailable in the original source.
index.html
Bonus: If you're interested in improving your PWA's performance, security, and usability, I recommend using Lighthouse, Google's open-source tool for auditing progressive web apps.
A tip from Luiz :P


