How to Build and Deploy a Progressive Web App with PWAFire, GitHub Pages, and Firebase

undefined or mostly null.
Search for a command to run...

undefined or mostly null.
Whatever troubles you may have with a resume, Elle Blonde with her newest article https://elleblonde.com/2021/04/02/perfect-resume-how-to-impress-employer/ can help you fix them. It did so with my CV!
In this series, I will share articles related to best practices for building and deploying applications on the web with the JavaScript and Python programming languages.
Chrome and Firefox have started showing insecure warnings on sites without SSL certificates. Without SSL, your website will show insecure to the visitors. Therefore, using an SSL-encrypted connection for safety, accessibility or PCI compliance reason...
I wrote this article in December 2023 for an interview screening task and thought to share it today while clearing my drafts for some new content prep, just in case it's still helpful to someone out t

Hey! I’m super excited to announce that I have joined the Secretariat Team at the Digital Public Goods Alliance. In this role, I leverage my passion for open source and technical background to assess DPG applications, provide technical support and ad...

Creative designs have become more important than ever in the software ecosystem today with many industries and end-consumers having several use cases that require them to offer design editing solutions to either designers or end-consumers. Every busi...

With the rise of artificial intelligence (AI) and large language models (LLMs), it has become easier to solve different human problems than ever before. Even consumers with little to no technical expertise can benefit from AI. Humans can now automate...

Some years ago, GitHub introduced the new Profile README feature that allowed GitHub users to pin a markdown file on their profile using a special repository named after their GitHub username. Since then, developers have used this file as a quick por...

Recently I discovered a new trend, a powerful web technology, one that every Web Developer should know, yeah I said every!
I first heard about PWA’s a few months back, and at first, it was weird trying to understand the concept and then trying to learn it. I stumbled on a link that led me to PWAFire an Open Sourced framework that helps you to Build Scalable Progressive Web Apps/First Experiences.
I started out by reading what PWA really means and why I should learn it. After understanding the entire concept, I decided to dive in.
As a Developer, one skill you should possess is “Learning”. What you knew yesterday might be obsolete today. It happens on the web from time to time that powerful technologies come to exist, if you are still behind, you’d miss out on this evolution.
So you should have heard of PWA or Progressive Web Apps and you probably might be wondering what this really means?
Basically a Progressive Web App is a mobile website that can perform super-fast and behave just like a mobile app.
A Progressive Web App (PWA) is a web app that uses modern web capabilities to deliver an app-like experience to users.
Now let's break this down!
Let's break the word Progressive Web App;
Progressive: happening or developing gradually or in stages.
Web: A common name for the World Wide Web, a subset of the Internet consisting of the pages that can be accessed by a Web browser.
App: An application, especially as downloaded by a user to a mobile device
Let's merge all this definition; a subset of the Internet consisting of the pages that can be accessed by a Web browser, happening or developing gradually or in stages and can be downloaded by a user to a mobile device.
To wrap up; A progressive Web App is a modern web application built with a number of specific technologies and standard patterns which allow them to take advantage of both web and native app features.
PWA helps us to build Cross-platform web apps (Works on the web, Android, iOS and Desktop)
Progressive Web Apps are installable and live on a user’s home screen, without the need for an app store. They offer an immersive full screen experience with help from a web app manifest file and can even re-engage users with web push notifications.
When you visit a website with PWA, It pops up with a notification telling you to add the website to your home screen. This is just like downloading an app from the App Store or Play Store.
I would be showing you shots from Netty-Finder a little project I built, you can contribute here.
Once you’ve clicked ADD, the website is then installed on your device and yes it acts like a mobile app.
You can uninstall it and share it; basically you use it as a normal Mobile App. Cool right?
PWA’s can also be installed on Android, iOS and Desktop.
Here’s how it looks on Desktop

So why should you build a PWA?
Building a high-quality Progressive Web App has incredible benefits, making it easy to delight your users, grow engagement and increase traffic.
The benefits of Progressive Web Apps are enormous — you can check more on Google Developers Docs.
The three baseline criteria a website must fulfil in order to qualify as a Progressive Web App are:
You need to be running under HTTPS.
You need a Web App Manifest.
You need a Service Worker.
Now, let's move to the Codelab section :)
We are going to convert a basic static site into a Progressive Web App.
Make sure to follow all the steps as documented later below.
Download the project template. Unzip the downloaded file to your preferred location after download.
If you are using GitHub Desktop, simply
Fork and
clone it. If you’re using
Git, git clone https://github.com/BolajiAyodeji/code-lab-demo.git
This project is a basic app built with HTML, CSS, BOOTSTRAP AND JAVASCRIPT.
The App checks your Date of Birth and detects the Day of the Week you were born. Pretty cool right? 😀
We are going to convert this web app into a Progressive Web App and test it using the PWAFire Checklist
In your root folder, create two empty files; service-worker.js and
manifest.json and save. Once done; let's proceed down here;
This is the first step to making our web app work offline. Copy and paste this code to the index file just before the end of the body tag or in the head tag.
N/B : YOU NEED HTTPS :
We are going to use Firebase Hosting and GitHub Pages later which shall have HTTPS already provisioned for our project.
First, we need to check if the browser supports service workers, and if it does, register the service worker.
<!-- register service worker -->
<script>
if ('serviceWorker' in navigator)
{
window.addEventListener('load', function() {
navigator.serviceWorker.register('/service-worker.js')
.then(function() { console.log("Service Worker Registered, Cheers to PWA Fire!"); });
}
);
}
</script>
<!-- end of service worker -->
We are going to add a link tag to all the pages that encompass our web app inside the head tag. For our case, we only have one page, the index.html. Add the following code to it.
<!-- start of web manifest -->
<link rel="manifest" href="/manifest.json">
<!-- end of web manifest -->
A service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don’t need a web page or user interaction.
NOTE : The important thing to understand about the Service Worker is that you are in control of the network. You get to decide what is cached, how it is cached and how it should be returned to the user.
Follow the steps in the code below, configure to your desired taste :)
/ PWA Fire Bundle
// after a service worker is installed and the user navigates to a different page or
// refreshes, the service worker will begin to receive fetch events
self.addEventListener('fetch', function(event) {
event.respondWith(caches.open('cache').then(function(cache) {
return cache.match(event.request).then(function(response) {
console.log("cache request: " + event.request.url);
var fetchPromise = fetch(event.request).then(function(networkResponse) {
// if we got a response from the cache, update the cache
console.log("fetch completed: " + event.request.url, networkResponse);
if (networkResponse) {
console.debug("updated cached page: " + event.request.url, networkResponse);
cache.put(event.request, networkResponse.clone());}
return networkResponse;
}, function (event) {
// rejected promise - just ignore it, we're offline!
console.log("Error in fetch()", event);
event.waitUntil(
caches.open('cache').then(function(cache) {
// our cache is named *cache* in the caches.open() above
return cache.addAll
([
//cache.addAll(), takes a list of URLs, then fetches them from the server
// and adds the response to the cache.
// add your entire site to the cache- as in the code below; for offline access
// If you have some build process for your site, perhaps that could
// generate the list of possible URLs that a user might load.
'/', // do not remove this
'/index.html', //default
'/index.html?homescreen=1', //default
'/?homescreen=1', //default
'/assets/css/main.css',// configure as by your site ; just an example
'/images/*',// choose images to keep offline; just an example
// Do not replace/delete/edit the manifest.js paths below
//These are links to the extenal social media buttons that should be cached;
// we have used twitter's as an example
'https://platform.twitter.com/widgets.js',
]);
})
);
});
// respond from the cache, or the network
return response || fetchPromise;
});
}));
});
self.addEventListener('install', function(event) {
// The promise that skipWaiting() returns can be safely ignored.
self.skipWaiting();
console.log("Latest version installed!");
});
Configuring the manifest.json file helps you to specify how you want your web
app to look like when launched on the device.
You can also use the WEB MANIFEST
GENERATOR to automatically generate your
manifest.json file
{
"background_color": "#fff",
"display": "standalone",
"orientation":"portrait",
"theme_color": "#fff",
"short_name": "DOB Finder",
"name": "Date of Birth Finder",
"description": "description or purpose of your progressive web app",
"lang": "en-US",
"icons": [
{
"src": "img/icons/icon-72x72.png",
"sizes": "72x72",
"type": "image/png"
},
{
"src": "img/icons/icon-96x96.png",
"sizes": "96x96",
"type": "image/png"
},
{
"src": "img/icons/icon-128x128.png",
"sizes": "128x128",
"type": "image/png"
},
{
"src": "img/icons/icon-144x144.png",
"sizes": "144x144",
"type": "image/png"
},
{
"src": "img/icons/icon-152x152.png",
"sizes": "152x152",
"type": "image/png"
},
{
"src": "img/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "img/icons/icon-384x384.png",
"sizes": "384x384",
"type": "image/png"
},
{
"src": "img/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "index.html?launcher=true",
}
PLEASE NOTE: When using your own logos, ensure that the image has equal width and height preferably (500px x 500px), sizes like 400px x 350px will result in errors! Find more starter guide on PWAFire Web Manifest developer docs available here.
In the head tag, add theme color to all your pages as shown in the code below; You could use the same theme color as in the manfest.json file.
<!-- theme-color -->
<meta name="theme-color" content="#fff" />
<!-- end-theme-color -->
If you’re new to Firebase, you’ll need to create your account and install some tools first.
Create a Firebase account at https://firebase.google.com/console/. Once your account has been created and you’ve signed in, you’re ready to deploy!
Create a new Firebase app at https://firebase.google.com/console/
For this codelab, name the projectDOB Finder and take note of the Project ID
The Firebase Command Line Interface (CLI) will allow you to serve the web app locally and deploy.
npm -g install firebase-tools
firebase --version
firebase login
Date of Birth Finder directorycd Date-of-Birth-Finder
Initialize your app to use Firebase.
Select your Project ID and follow the instructions.
When prompted, you can choose any Alias, such as pwafire for instance. Select
Firebase Hosting as the Firebase CLI feature. Provide the default directory
as /. To the other prompts, reply NO; N
firebase init
firebase deploy
https://YOUR-FIREBASE-APP.firebaseapp.com
You should see an “install to home screen” banner prompt!
Welcome to the new world!! Further reading: Firebase Hosting Guide.
If you’re new to GitHub, you’ll need to create your account and create a repository first.
Create a GitHub account at https://github.com/signup. Once your account has been created and you’ve signed in, you’re ready to start!
Create a new Repository https://github.com/new named username.github.io, where username is your username (or organization name) on GitHub.
If you created a repository with your username before, don’t worry, just name
the Repository anything, your project would still be hosted on the url
username.github.io/project-name where username is your username (or organization name) on GitHub and project-name is the name of your project repository
For this codelab, name the repositoryDOB Finder
Enable GitHub Pages https://github.com/repository-name/settings, where repository-name is the name of your repository on GitHub.
Scroll down to the GitHub Pages section,Click the NONE Drop down button, Select master branch, Click Save.
Upload your files to your repository
Using GitHub Desktop [Download GitHub Desktop ]
Using Git Terminal. [Download here]
Clone the Repository
$ git clone https://github.com/username/username.github.io
Enter the Project folder
$ cd username.github.io
Add your files to the cloned repository folder
Add, Commit and Push your Changes
$ git add -all
$ git commit -m "Initial commit"
$ git push -u origin master
https://username.github.io
View the Demo App here
Check out the Progressive Web Apps Checklist in this codelab and check if your web app qualified enough to be a called a PWA.
You can also use LightHouse in Chrome Dev Tools to checklist your web app.
Also, PWAFire is an Open Sourced tool built by Maye Edwin that helps you build amazing web experiences by providing you with web.dev guide and tool-kits that helps you build progressive web apps with best web practices. One major aspect of PWAFire I enjoy most is the Codelabs section :)
You can join the build and contribute here
If you still have problems with building your PWA, you can tweet to me @iambolajiayo, I will respond asap!
Thank you for reading, If you did enjoy this article, share!! :)