The Basics of Creating a Progressive Web App Using React.js
Progressive Web Applications (PWAs) are a hybrid between a standard webpage and a mobile app. They allow users to access the PWA from their computers, but they offer the sleek, fluid design of a mobile application.
As PWAs become more popular, the desire to build them has increased, as well. If you’re wondering how to build a progressive web app using React.js, you’re not alone. The basic steps to building a PWA in React.js are as follows.
Before you begin setting up your PWA, you’ll want to decide on a server in which to build. Once you know where you want the PWA to be, generate a basic React application using create-react-app.
When you’re ready, switch to the server you want to build in and run the following.
npm install -g create-react-app
After that, you’ll need to install something called React Router.
npm install --save email@example.com
Now you need to run the standard gist in your App.js. You can easily find the gist by searching “PWA in React.js gist” or something similar. After you run the standard gist, you’ll have created a basic layout with a few navigation options.
If this is sounding foreign to you already, you might want to consider React 16 training before going further as it may help you fully understand the process and can better ensure success.
Lighthouse is a free tool that Google has created for developers who are building PWAs. Google has a PWA checklist against which it tests your PWA (using Lighthouse) for quality and completeness.
It’s a simple Chrome extension that you can get from the Google Developers suite. Just search Lighthouse and you’ll find it. Once it’s installed, click Generate Report and you’ll get a comprehensive report on how your PWA is doing.
Service worker setup
Basically, it’s what enables your PWA to work offline. The process is a bit lengthy and complex, but you can find all the code you need online. If you’re not good with code or you’re just starting out, you might seek training instead.
Run Lighthouse after each step to see how you’re doing.
Once you’ve added progressive enhancement, check your app with Lighthouse again. If your score is higher, you’ve done it correctly.
Adding home screen capabilities
One of the main “selling points” of a PWA is the ability to save it to your home screen and run it just like an app. To do that, you have to add home screen capabilities to your code.
Doing this requires you to install a manifest.json file to the public directory on your server. You can find the lengthy code for this online. You’ll also need an icon.png to use.
Once you’ve done all that, you’ll add a couple more lines of code to the PWA and run Lighthouse once more. Your score should be significantly higher at this point.
At this point, the only things you should be missing are caching and https, both of which can be taken care of during deployment. To deploy your PWA, you’ll probably want to use Firebase.
You’ll want to run a new pwa-experiment in the Firebase console and run the following code in your project folder.
npm install -g firebase-tools
Once you complete the rest of the deployment process, you’ll have a PWA. Sort of. At the very least, Lighthouse should rank you at 100 percent. But many enhancements and design elements will be missing, even if you follow basic tutorials.
The beauty of PWAs is that you can make them whatever you want them to be. Whether your PWA is educational or for entertainment purposes, being able to create it in such a way that it can operate with the unique functional capabilities of a PWA can only enhance the end project.
If you’re still confused as to how to build a progressive web app using React.js, you can obtain training from a variety of services to get a better handle on the process and develop more dynamic and impactful PWAs for your audience.