What are progressive web apps?

A progressive web app (PWA) is an innovative web-based application that surpasses the limitations of traditional websites, emulating the behavior of native applicationsNative applications are software programs developed for a specific platform or operating system, utilizing the platform’s native programming languages and tools.. By harnessing advanced web technologies, PWAs deliver an exceptional user experience, blending website and native app features. They offer enhanced performance, offline functionality, and a seamless interface. PWAs seamlessly integrate into existing web platforms, elevating the overall user experience. Leveraging modern web technologies, PWAs provide offline capabilities, push notifications, and access to device hardware, bridging the gap between websites and native apps.

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.

Characteristics:

Some of the key characteristics of progressive web apps (PWAs) are as follows:

  • Cross-platform compatibility: PWAs can run on multiple platforms and devices— including desktops, smartphones, and tablets—without the need for platform-specific development.
  • Responsive design: PWAs adapt and provide an optimal user experience across different screen sizes and orientations.
  • Offline functionality: PWAs can work offline or in low-connectivity situations, allowing users to access content even without an internet connection.
  • App-like experience: PWAs offer an immersive and app-like experience with features such as home screen installation, full-screen mode, and access to device capabilities.
  • Fast loading and performance: PWAs are designed to load quickly and deliver smooth performance, providing a seamless user experience.
  • Discoverability: PWAs can be discovered through search engines or URLs, eliminating the need for app store approvals or installations.
  • Easy updates and maintenance: PWAs can be easily updated on the web, ensuring that users always have the latest version without requiring manual updates or app store submissions.

Fundamental requirements:

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.

Build react progressive web app (PWA)

To create a basic progressive web app using React, follow these steps:

  1. Ensure that you have React and Create React App installed. If not, install them by running the following command:
npm install -g create-react-app
  1. Create a new React app by executing the following commands:
npx create-react-app my-pwa-app
cd my-pwa-app
  1. Open the 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();
  1. Create a new file src/serviceWorkerRegistration.js with the following content:
// Registering the service worker
export 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);
});
});
}
}
  1. Create a new file 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;
  1. Build your progressive web app by running the following command:
npm run build
  1. Install the serve package globally by executing the command:
npm install -g serve
  1. Serve your app using the following command:
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;
React PWA: simple calculator

Conclusion

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.

Copyright ©2024 Educative, Inc. All rights reserved