Our Global Presence
Canada
57 Sherway St,
Stoney Creek, ON
L8J 0J3
India
606, Suvas Scala,
S P Ring Road, Nikol,
Ahmedabad 380049
USA
1131 Baycrest Drive,
Wesley Chapel,
FL 33544
In this article, you will learn about the progressive web app, and why PWA is gaining popularity, and also you can create a simple PWA app using NextJs.
PWA = web + experience of a native application
What is PWA?
The progressive web app is a simple web application that runs on a web browser similar to that of a website and provides an installable feature on a mobile device. PWA gives you a rich mobile experience via native-like functionalities such as the ability to work offline, push notifications, device hardware accessibility, and many more. Web applications can reach anyone, anywhere, on any device with a single codebase as a result PWA is more special. PWA offers the same experience as the native app and you need not download it from an app store or play store. PWA loads runs and functions in a web browser.
The Native app is known for rich and reliable with its own standalone user experience, the web app are best for reachability. Progressive Web Apps combine the best features of both native and web apps, including native-like functionality, dependability across all platforms with a single codebase, installability, and accessibility to anyone, anywhere. They are designed, developed, and enhanced using cutting-edge and modern APIs.
Why PWA?
Some people may wonder why we need PWA if we can have a separate version of apps like android, IOS, and web. The PWA is gaining popularity because of the following features:
You will use NEXTJS to implement the PWA which is a react framework for developing feature-rich frontend web applications. Now, Let’s create the project executing any commands mentioned below in your terminal based on the package management tool that you have.
npx create-next-app@latest --ts # or yarn create next-app --typescript # or pnpm create next-app --ts
After executing the command you will have a pre-configured NextJs project.
Now you will work on the implementation of PWA in the project that you just configured. For PWA implementation you will make use of next-pwa which is a zero-config PWA Plugin for NextJs. Let’s install the plugin in the project using the command below:
yarn add next-pwa npm install next-pwa
Now, update or create next.config.js
/** @type {import('next').NextConfig} */ const runtimeCaching = require("next-pwa/cache"); const withPWA = require("next-pwa")({ disable: process.env.NODE_ENV === "development", dest: "public", register: true, skipWaiting: false, runtimeCaching, }); const nextConfig = withPWA({}); module.exports = nextConfig;
After running next build, this will generate two files in your public: workbox-*.js and sw.js, which will automatically be served statically.
This step is optional. So if you want to use a custom server then you can proceed with this step. To create a custom server using express the root of the project with the file name server.js in order to load the service work. For creating the express server, you need to add express into the project
yarn add express npm install express
const express = require("express"); const next = require("next"); const port = parseInt(process.env.PORT, 10) || 3000; const dev = process.env.NODE_ENV !== "production"; const app = next({ dev, }); const handle = app.getRequestHandler(); app.prepare().then(() => { const server = express(); server.get("/service-worker.js", (req, res) => { app.serveStatic(req, res, "./.next/service-worker.js"); }); server.get("*", (req, res) => { return handle(req, res); }); server.listen(port, (err) => { if (err) throw err; }); });
You have to generate the manifest file inside the public folder in the project. For this, you can use any online tool for generating the manifest file.
Fill in all the information and generate the manifest file. After that copy the content into the public directory and rename the file as manifest.json
So now lets _document.tsx page and include the manifest.json link inside the Head tag as below:
import Document, { Html, Head, Main, NextScript } from "next/document"; class MyDocument extends Document { render() { return ( <Html> <Head> <link rel="manifest" href="/manifest.json" /> <link rel="apple-touch-icon" href="/logo.png"></link> <meta name="theme-color" content="#fff" /> </Head> <body> <Main /> <NextScript /> </body> </Html> ); } } export default MyDocument;
You have successfully configured your project with PWA up to this point. Now run the following command and build the project.
yarn build npm build
After build completion starts the build app using the following command:
yarn start npm start
When the app is started, you can see an install icon at the top of the browser like in the above image. Now you can install and use the app.
For more information and to develop web application using React JS, Hire React Developer from us as we give you a high-quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – hello@hkinfosoft.com or Skype us: “hkinfosoft”.
To develop custom web apps using React JS, please visit our technology page.
Content Source:
57 Sherway St,
Stoney Creek, ON
L8J 0J3
606, Suvas Scala,
S P Ring Road, Nikol,
Ahmedabad 380049
1131 Baycrest Drive,
Wesley Chapel,
FL 33544
57 Sherway St,
Stoney Creek, ON
L8J 0J3
606, Suvas Scala,
S P Ring Road, Nikol,
Ahmedabad 380049
1131 Baycrest Drive,
Wesley Chapel,
FL 33544
© 2024 — HK Infosoft. All Rights Reserved.
© 2024 — HK Infosoft. All Rights Reserved.
T&C | Privacy Policy | Sitemap