Convert your Website into an APP with 3 easy steps

Search for a command to run...

Glad to know you liked it
I've already tried to make a PWA before even knowing what really is it thru one of the web.dev lessons. I just follow the instructions and I thought I'm just making a responsive website but not. There's a lot to it that I don't really know, but I enjoyed it because it's so cool. These past few days I'm learning more knowledge about it and I find your post helpful. Thanks.
I am happy knowing it was helpful
Was just hearing about PWA's yesterday at work and nice to see an article pop up here at this platform
Haha nice
Yes it is
Linux Commands are like GTA Cheatcodes. People with great memory remember them by heart and weaker ones write them down. I am a hybrid, I used to remember most of the linux commands and GTA Cheatcodes but I don't have them byheart anymore Here is why...

Job-Stash is an alternative to node-schedule that persists job, supports atomic execution and has inbuilt retry mechanism

Here is how I wrote this blog post. I remembered things I contributed last year. made them into points and started expanding on how anyone can implement/learn that. Then realised the blog post is getting long :) Anyways, Hey everyone, I am Hrithwik, ...

I spent the last week improving the performance of a few APIs at work and improved response Times by 5X. I just did 3 basic things which improved performance in most of the API routes. This blog is really helpful especially if you are new to Javascri...

A few days back, I uninstalled the Twitter app and switched to the web app and I noticed something, Twitter had like a different/modern Installation UI for its PWA. (Know more about PWAs here.) I was like, Woah, this looks so dope and better than t...

There are several websites which let you convert your website into an Android/IOS app, But in reality, They provide a web view of the website with tons of watermark
Instead of using these services let me tell you about PWA's and how you can convert your website into a Progressive Web Application (PWA) by following 3 easy steps.

** Progressive Web Applications ** is a technology built by Google developers which allow developers to add native looks and some features like offline load & Push Notifications to your website.

Easy Installation for users: It just take few seconds to install PWAs and they are lightweight which is the reason why Instagram lite and Facebook lite is basically a PWA.
Easy to build: Web technologies are easier to learn than native development and numbers of developers required to build a project is also less.
Cost-Effective: With one code base your website can run on android phones, iPhones and Windows Computers.
Better Performance: With image and code caching the performance is increased drastically.
Basics of HTML and JavaScript
Current Website should load with HTTPS
Current Website should be responsive
These are the three files needed to convert your current website into an installable PWA.

This is the file which helps you add splash screens and icons to your app. In this file, you specify basic metadata like your app name, icon size, icon directory and start URL of your website.
Here is my Manifest.JSON which you can copy and replace it with your details.
{
"name": "Hrithwik Bharadwaj",
"short_name": "Hrithwik",
"description": "Portfolio PWA of Hrithwik Bharadwaj",
"icons": [
{
"src": "/assets/img/icons/512x512.png",
"type": "image/png",
"sizes": "512x512"
},
{
"src": "/assets/img/icons/256x256.png",
"type": "image/png",
"sizes": "256x256"
},
{
"src": "/assets/img/icons/192x192.png",
"type": "image/png",
"sizes": "192x192"
}
],
"start_url": "/",
"scope": "/",
"dir": "ltr",
"background_color": "#111111",
"display": "standalone",
"theme_color": "#111111",
"orientation": "portrait",
"prefer_related_applications": false
}
This might be confusing to understand if you are a beginner so just check out this manifest generator to generate icons and later download the file.
Also don't forget to Include this in your HTML file
<link href="/static/manifest.json" rel="manifest">

This file helps in making your app work offline by caching important files. If you have worked on React or Vue Projects this file is usually shipped along.
Here I am using WorkBox API for service worker as its very simple. Just create a file called sw.js and paste the below code there.
if ('undefined' === typeof window) {
importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js');
}
workbox.core.skipWaiting();
workbox.core.clientsClaim();
if (workbox) {
console.log(`Yay! Workbox is loaded 🎉`);
workbox.precaching.precacheAndRoute([
{
"url": "/",
"revision": "1"
}
]);
workbox.routing.registerRoute(
/\.(?:js|css)$/,
new workbox.strategies.StaleWhileRevalidate({
cacheName: 'static-resources',
}),
);
workbox.routing.registerRoute(
/\.(?:png|gif|jpg|jpeg|svg)$/,
new workbox.strategies.CacheFirst({
cacheName: 'images',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 60,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
}),
],
}),
);
workbox.routing.registerRoute(
new RegExp('https://fonts.(?:googleapis|gstatic).com/(.*)'),
new workbox.strategies.CacheFirst({
cacheName: 'googleapis',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 30,
}),
],
}),
);
} else {
console.log(`Boo! Workbox didn't load 😬`);
}
workbox.googleAnalytics.initialize();
Now that you have created an sw.js file just add the link to it on your HTML page.
<script src="sw.js"> </script>

This part is the one which will allow you to get automatic "install now" prompt.
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register("sw.js", {scope: '/'})
.then(registration => {
console.log("ServiceWorker running");
})
.catch(err => {
console.log(err);
})
}
</script>
Copy this and add it in your HTML file.
After you add these things. To check if everything is working fine, Use Lighthouse in chrome and check if it is showing a PWA sign.

PWA's can have many other features and even have a different type of service worker. Above code was the easiest implementation for beginners.
Below are some small things which you can add.
You can do something like this where the button hides after installation using this code some simple JavaScript code and CSS.

From BookMyShow to Instagram everyone sends Push Notifications from PWA to their users. This can be implemented using OneSignal or Firebase Cloud Functions

If you have a small team which has already built a mobile first website than it's easier to switch to PWA.
To be honest, it's a temporary fix until your native app is getting ready.
Yeah sure, PWA looks like a mobile app but it isn't as smooth as a native app. A lot of developers like me are waiting for PWA's to become smooth.
(Update: There is also a new kind of Installation Widget that twitter started using for it's PWA - Here is short guide on it.)