A progressive web app (PWA) is an innovative web-based application that surpasses the limitations of traditional websites, emulating the behavior of
Weather PWAs are a perfect example of how PWAs can offer users a fast, reliable, and engaging weather forecasting experience, allowing them to stay informed about current and future weather conditions, all within a single web-based application.
Some of the key characteristics of progressive web apps (PWAs) are as follows:
An app is considered a progressive web app (PWA) if it includes the following:
HTTPS or non-HTTPS localhost: PWAs should be served over a secure HTTPS connection or be accessible through non-HTTPS localhost during development.
A manifest.json
file for interface definition: PWAs require a manifest.json
file that defines their interface, including metadata and display preferences.
Service worker for background functionality: PWAs employ a service worker, a background script that enables offline functionality, caching, and push notifications.
Responsive and app-like experience: PWAs should provide a responsive design and a user experience similar to native apps.
Offline capability through core asset caching: Well-designed PWAs can run offline by caching essential assets like HTML, CSS, JavaScript, and logos.
To create a basic progressive web app using React, follow these steps:
npm install -g create-react-app
npx create-react-app my-pwa-app
cd my-pwa-app
src/index.js
file and modify it as follows:import React from 'react';import ReactDOM from 'react-dom';import './index.css';import * as serviceWorkerRegistration from './serviceWorkerRegistration';import App from './App';ReactDOM.render(<React.StrictMode><App /></React.StrictMode>,document.getElementById('root'));serviceWorkerRegistration.register();
src/serviceWorkerRegistration.js
with the following content:// Registering the service workerexport function register() {if ('serviceWorker' in navigator) {window.addEventListener('load', () => {navigator.serviceWorker.register('/service-worker.js').then(registration => {console.log('Service worker registered:', registration);}).catch(error => {console.log('Service worker registration failed:', error);});});}}
src/App.js
with the following content:import React from 'react';function App() {return (<div className="App"><h1>Welcome to My Progressive Web App</h1><p>Enjoy the app-like experience!</p></div>);}export default App;
npm run build
serve
package globally by executing the command:npm install -g serve
serve -s build
These steps will help you create and run a basic progressive web app using React.
const reportWebVitals = onPerfEntry => { if (onPerfEntry && onPerfEntry instanceof Function) { import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { getCLS(onPerfEntry); getFID(onPerfEntry); getFCP(onPerfEntry); getLCP(onPerfEntry); getTTFB(onPerfEntry); }); } }; export default reportWebVitals;
Progressive web apps represent a big advancement in the application development industry. Both mobile applications and websites play an important role in improving the consumer experience. PWAs are a step further in this direction. They blend the greatest features of both the mobile app and the website.
Free Resources