Back to home

Progressive web apps

Laurens Duin - June 2023

In today's digital landscape, with more devices, platforms, and browsers than ever, it keeps getting harder to build a seamless user experience for all users. Progressive Web Apps (PWAs) have emerged as a powerful solution, combining the best of web- and native applications. In this article, we will discuss the benefits and features of PWAs, like offline capabilities, push notifications, and app-like experiences.

Benefits of PWAs:

To show a simple example of how service workers can be used to implement offline functionality, take a look at the code below.

				
const offlineCacheName = 'offline';
const offlineCacheFiles = [
	'/main.css',
	'/offline.html',
	'/manifest.json',
	'/fonts/pokemon-fire-red.woff2',
	'/img/favicon.png',
];

self.addEventListener('install', (event) => {
	event.waitUntil(
		(async () => {
			const cache = await caches.open(offlineCacheName);
			await cache.addAll(offlineCacheFiles);
		})()
	);
});


self.addEventListener('fetch', async (event) => {
	event.respondWith(
		fetch(event.request)
			.then((response) => {
				return response;
			})
			.catch(async () => {
				// If there's no network, serve the cached response
				const response = await caches.match(event.request);
				if (response) {
					return response;
				} else {
					// If there's no cached response, serve the fallback HTML page
					return caches.match('/offline.html');
				}
			})
	);
});
					
				
			

Now, this code is a pretty simple example which serves a static fallback page if there's no connectivity. However, much more advanced service-workers can be written. Certain websites could even be almost entirely functional without an internet connection.

Features of PWAs:

Conclusion:

Progressive Web Apps have opened up new possibilities for interacting on the web, blurring the lines between web and native experiences. With their offline capabilities, push notifications, and app-like interfaces, PWAs offer users an engaging and reliable experience, regardless of their internet connectivity. As more businesses and developers embrace PWAs, we can expect to see a new era of web applications that combine the best features of both worlds. After a smaller assignment I did using PWAs, I wasn't fully convinced of the benefits of PWAs. However, after writing this article and diving into the subject a bit more, I have come to appreciate the benefits of PWAs. I think this is a technology that will become more and more important in the future.