<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Chimgee G on Medium]]></title>
        <description><![CDATA[Stories by Chimgee G on Medium]]></description>
        <link>https://medium.com/@oyuhaanaa?source=rss-23679b72c136------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GzEu2HOFnSjc1Q4G.</url>
            <title>Stories by Chimgee G on Medium</title>
            <link>https://medium.com/@oyuhaanaa?source=rss-23679b72c136------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 00:23:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@oyuhaanaa/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Part2: Implement authentication in next js v15 using next-auth v5, prisma, postgres db]]></title>
            <link>https://medium.com/delivus/part2-wip-implement-authentication-in-next-js-v15-using-next-auth-v5-prisma-postgres-db-78a950e63dda?source=rss-23679b72c136------2</link>
            <guid isPermaLink="false">https://medium.com/p/78a950e63dda</guid>
            <category><![CDATA[nextauth]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Chimgee G]]></dc:creator>
            <pubDate>Fri, 04 Apr 2025 06:56:22 GMT</pubDate>
            <atom:updated>2025-04-04T06:56:39.600Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 2: Setup NextAuth and Implement Sign-in</h3><p>This post covers <strong>Part 2</strong> of the implementation, focusing on setting up Next auth and implementing sign-in logic in a Next.js 15 project. You can see part 1 from <a href="https://medium.com/delivus/how-to-implement-authentication-in-nextjs-15-using-next-auth-prisma-postgres-db-part-1-bc1b90d60d51">here</a>.</p><h3>Topics Covered in This Section:</h3><ol><li>Creating NextAuth Configuration</li><li>Protecting Routes</li><li>Implementing Credential provider</li><li>Implementing Login Form</li></ol><h3>1. Creating NextAuth configuration</h3><p>Step 1: Install next-auth dependency:</p><pre>yarn add next-auth@beta</pre><p>next-auth 5 version is in pre production launch version.</p><p>Step 2: Create an auth.config.ts file in the root directory of the project, which will contain NextAuth configuration options, and export it.</p><pre>import type { NextAuthConfig } from &#39;next-auth&#39;;<br> <br>// Creating the configuration object for NextAuth<br>export const authConfig = {<br>  // Defining signup pages to tailor the authentication experience. Here, we redirect the default sign-in page to &#39;/login&#39;.<br>  pages: {<br>    signIn: &#39;/auth/signin&#39;,<br>  },<br>  providers: []<br>} satisfies NextAuthConfig;</pre><p>Step 3: Generating secret key</p><p>This key is used to encrypt cookies, ensuring the security of user sessions. You can do this by running the following command in your terminal:</p><pre>openssl rand -base64 32</pre><p>Then, in your .env file we created in the Part 1, add your generated key to the AUTH_SECRET variable:</p><pre>AUTH_SECRET=your-secret-key</pre><h3>2. Protecting Routes</h3><p>Now, it is time to protect private routes from public access.</p><p>Step 1: To do that, implement the <strong>authorized callback</strong> in authConfig.</p><p>Let’s assume your public page starts with a “auth” and others are private pages.</p><pre>import type {NextAuthConfig} from &#39;next-auth&#39;;<br><br>export const AUTH_PATH = &quot;/auth&quot;;<br>// Creating the configuration object for NextAuth<br>export const authConfig = {<br>    trustHost: true,<br>    // Defining signup pages to tailor the authentication experience. Here, we redirect the default sign-in page to &#39;/login&#39;.<br>    pages: {<br>        signIn: AUTH_PATH + &#39;/signin&#39;,<br>    },<br>    // Configuring callbacks for handling authorization logic during authentication flow.<br>    callbacks: {<br>        authorized({auth, request: {nextUrl}}) {<br>            // Checking if the user is logged in<br>            const isLoggedIn = !!auth?.user;<br>            // Determining if the user is currently on the dashboard<br>            const isOnAuth = nextUrl.pathname.startsWith(AUTH_PATH);<br>            // Handling authorization logic based on user status and location<br>            if (!isOnAuth) {<br>                // Redirecting unauthenticated users to the login page when attempting to access dashboard-related pages<br>                return isLoggedIn;<br>            } else if (isLoggedIn) {<br>                // Redirecting authenticated users to the dashboard if they attempt to access authentication-related pages like login/signup<br>                return Response.redirect(new URL(&#39;/&#39;, nextUrl));<br>            }<br>            // Allowing access for other scenarios<br>            return true;<br>        },<br>    },<br><br>    // Placeholder array for authentication providers. We initialize it as empty for now, adding providers when required.<br>    providers: [], // We start with an empty array, adding providers as needed<br><br>} satisfies NextAuthConfig;</pre><ul><li>The <strong>authorized callback</strong> is used to verify if the request is authorized to access certain pages</li><li>The providers is list of login options such as username and password, google, facebook login etc. Currently, we provide empty list here.</li></ul><p>Step 2: The <strong>authorized callback</strong> protects private pages via <a href="https://nextjs.org/docs/app/building-your-application/routing/middleware">Next.js Middleware</a>. To do that, add an authConfig into middleware.ts file in root directory.</p><pre>import NextAuth from &#39;next-auth&#39;;<br>import { authConfig } from &#39;./auth.config&#39;;</pre><pre>export default NextAuth(authConfig).auth;</pre><pre>export const config = {<br>    // &lt;https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher&gt;<br>    matcher: [&#39;/auth&#39;, &#39;/((?!api|_next/static|_next/image|.*\\\\.svg).*)&#39;],<br>};</pre><p>Middleware is called before a request is completed and protects private routes before it is even rendered.</p><h3>3. Adding the Credentials provider</h3><p>The Credentials provider allows users to log in with a username and a password.</p><p>Step 1: Install dependency:</p><pre>yarn add zod</pre><p>You can use zod to validate values that user entered before checking if the user exists in the database:</p><p>Step 2: Create auth.ts file in root directory:</p><p>This file will import the next auth configuration and initialize NextAuth. Then add credential provider in providers list and implement authorize logic.</p><pre>import NextAuth from &#39;next-auth&#39;;<br>import { authConfig } from &#39;./auth.config&#39;;<br>import {prisma} from &quot;ospring/app/lib/prisma&quot;;<br>import bcrypt from &#39;bcryptjs&#39;;<br>import Credentials from &#39;next-auth/providers/credentials&#39;;<br>import {findUserByPhone} from &quot;ospring/app/db/user&quot;;<br> <br>export const { auth, signIn, signOut } = NextAuth({<br>  ...authConfig,<br>  providers: [Credentials({<br>            async authorize(credentials) {<br>                // Parsing and validating incoming credentials using Zod<br>                const parsedCredentials = signinSchema<br>                    .safeParse(credentials);<br>                if (parsedCredentials.success) {<br>                    const {phone, password} = parsedCredentials.data;<br>                const user = await findUserByPhone(phone); //fetch user info from database<br>                    console.log(&#39;authorize user:&#39;, user);<br>                    // If user exists, compare hashed passwords<br>                    if (!user) return null;<br>                    console.log(&#39;authorize user:&#39;, user);<br>                    const passwordsMatch = await bcrypt.compare(password, user.password);<br>                    // If passwords match, return the user<br>                    if (passwordsMatch) return user;<br>                // If credentials are invalid, log and return null<br>                console.log(&#39;Invalid credentials&#39;);<br>                return null;<br>            },<br>        })],<br>});</pre><p>Step 3: Create the route.ts file within api/auth/[…nextauth] according to the documentation. route.ts file should export GET, POST method.</p><pre>export {GET, POST} from &#39;@/auth&#39;;</pre><h3>4. Implementing Login Form</h3><p>Step 1: Create authenticate action:</p><p>Generate auth.ts file in app/actions directory.</p><pre>&#39;use server&#39;<br>import {signIn} from &quot;ospring/auth&quot;;<br>import {AuthError} from &quot;next-auth&quot;;<br>interface SigninFormState {<br>    success?: string;<br>    errors?: {<br>        phone?: string[];<br>        password?: string[];<br>        _form?: string[];<br>    };<br>}<br>// Authenticating function for sign-in<br>export async function authenticate(prevState: SigninFormState | undefined, formData: FormData) {<br>    console.log(&quot;authenticate&quot;, formData);<br>    try {<br>        await signIn(&#39;credentials&#39;, formData);<br>    } catch (error) {<br>        console.log(&quot;authenticate error: &quot;, error);<br>        // Handling authentication errors<br>        if (error instanceof AuthError) {<br>            switch (error.type) {<br>                case &#39;CredentialsSignin&#39;:<br>                    return {<br>                        errors: {<br>                            password: [&#39;Invalid credentials.&#39;],<br>                        }<br>                    };<br>                default:<br>                    return {<br>                        errors: {<br>                            password: [&#39;Something went wrong.&#39;],<br>                        }<br>                    };<br>            }<br>        }<br>        throw error;<br>    }<br>};</pre><h3>4. Creating the login route</h3><p>Step 1: Create page.tsx in /app/(pages)/auth/signin directory and paste the following code:</p><p>Its content will be like the following.</p><pre>&quot;use client&quot;<br>import {authenticate} from &quot;ospring/app/actions/auth&quot;;<br>import {useActionState} from &quot;react&quot;;<br>import {Button, Input} from &quot;ospring/app/components/ui&quot;;<br><br>export default function SigninForm() {<br>    console.log(&quot;Login page&quot;);<br>    const [errorMessage, action] = useActionState(authenticate, undefined);<br><br>    return (<br>        &lt;form action={action} id={&quot;login&quot;} className={&quot;h-full flex flex-col pt-10 items-center&quot;}&gt;<br>            &lt;div className={&quot;text-foreground m-10 text-xl&quot;}&gt;Login&lt;/div&gt;<br>            &lt;Input className={&quot;mb-4&quot;} maxLength={8} inputSize={&quot;medium&quot;} name={&quot;phone&quot;} placeholder={&quot;0000 0000&quot;}<br>                   label={&quot;Phone number&quot;}/&gt;<br>            &lt;Input maxLength={36} inputSize={&quot;medium&quot;} name={&quot;password&quot;} type=&quot;password&quot; placeholder={&quot;******&quot;}<br>                   label={&quot;Password&quot;}<br>                   errorMessage={errorMessage?.errors?.password ? errorMessage?.errors?.password[0] : &quot;&quot;}/&gt;<br>            &lt;Button className={&quot;bg-foreground text-background h-10 w-full mt-auto&quot;} type={&quot;submit&quot;}&gt;Login&lt;/Button&gt;<br>        &lt;/form&gt;<br>    )<br>}  </pre><p>You will notice the page imports Button and Input components in this blog, but we skip explaining content of those file. You can check their content from github repository.</p><h3>Try the project</h3><p>Finally, run the project:</p><pre>yarn dev</pre><p>You will see login page rendered in the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*85OHZI5CaV8YsWsm6t0s1g.png" /></figure><h3>Final Project Structure</h3><p>Your final project structure should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*Nq6VaoXAGExeZ0UvWY1zeA.png" /></figure><p>You can find the source code for this example <a href="https://github.com/delivus-daas/next-sample-app/tree/PART2_nextauth">here</a>.</p><h3>References:</h3><p><a href="https://nextjs.org/learn/dashboard-app/adding-authentication">https://nextjs.org/learn/dashboard-app/adding-authentication</a></p><p><a href="https://medium.com/@pawanrijal/building-authentication-in-a-next-js-14-app-using-nextauth-and-prisma-59c9d67a0eca">https://medium.com/@pawanrijal/building-authentication-in-a-next-js-14-app-using-nextauth-and-prisma-59c9d67a0eca</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78a950e63dda" width="1" height="1" alt=""><hr><p><a href="https://medium.com/delivus/part2-wip-implement-authentication-in-next-js-v15-using-next-auth-v5-prisma-postgres-db-78a950e63dda">Part2: Implement authentication in next js v15 using next-auth v5, prisma, postgres db</a> was originally published in <a href="https://medium.com/delivus">딜리버스</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to implement authentication in nextjs 15 using next-auth, prisma, postgres db: Part 1]]></title>
            <link>https://medium.com/delivus/how-to-implement-authentication-in-nextjs-15-using-next-auth-prisma-postgres-db-part-1-bc1b90d60d51?source=rss-23679b72c136------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc1b90d60d51</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[nextjs-app-router]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[prisma-orm]]></category>
            <dc:creator><![CDATA[Chimgee G]]></dc:creator>
            <pubDate>Fri, 17 Jan 2025 02:12:09 GMT</pubDate>
            <atom:updated>2025-04-04T06:58:14.773Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we’ll create a simple Next.js application with a <strong>Sign In </strong>page, and a dashboard. To accomplish this, we’ll use the following tools:</p><ul><li><strong>Framework:</strong> <a href="https://nextjs.org/">Next.js</a></li><li><strong>Database:</strong> <a href="https://www.postgresql.org/">PostgreSQL</a></li><li><strong>ORM:</strong> <a href="https://www.prisma.io/">Prisma</a> (for database management)</li><li><strong>Authentication:</strong> <a href="https://next-auth.js.org/">NextAuth</a> (<a href="https://www.notion.so/Why-should-we-use-nextauth-17024414f57f8015a909db31b9fa57aa?pvs=21">Why NextAuth?</a>)</li><li><strong>Validation:</strong> <a href="https://zod.dev/">Zod</a></li></ul><p>This post covers <strong>Part 1</strong> of the implementation, focusing on setting up Prisma in a Next.js 15 project.</p><h3>Topics Covered in This Section:</h3><ol><li>Creating a Project</li><li>Setting up Prisma</li><li>Generating Database Tables</li><li>Generating Prisma Client</li><li>Seeding the Database with Dummy Data</li><li>Inserting and fetching Data from Tables</li></ol><h3>1. Create a Next.js Project</h3><p>Use the create-next-app CLI to generate a Next.js application:</p><pre>npx create-next-app@latest [project-name] [options]</pre><p>We created a sample project using the following options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z8su5xkhWZl2Q-cpwljGPg.png" /></figure><p>Here, we use “ospring” as a root directory alias, you can use any text instead of that.</p><p>Run the following command, and you will see sample nextjs page rendered in your browser.</p><pre>yarn dev</pre><h3>2. Set Up Prisma</h3><p>Step 1: Install Prisma</p><p>Navigate to the project’s root directory and install Prisma as a development dependency:</p><pre>yarn add -D prisma;</pre><p>Step 2: Initialize Prisma</p><p>Run the following command to initialize Prisma in your project:</p><pre>npx prisma init</pre><p>This creates a prisma/schema.prisma file with the following content:</p><pre>generator client {<br>  provider = &quot;prisma-client-js&quot;<br>}</pre><pre>//connection to DB<br>datasource db {<br>  provider = &quot;postgresql&quot;<br>  url      = env(&quot;DATABASE_URL&quot;)<br>}</pre><p>Step 3: Configure the .env File</p><p>Create .env file in root directory and add your database connection string to the .env file in the project’s root directory:</p><pre>//file name: .env<br>DATABASE_URL=postgresql://your_user_name:your_user_password@localhost:port/your_database_name?sslmode=ospring</pre><p>We assume that you’ve already prepared database server. If not, please read <a href="https://www.devart.com/dbforge/postgresql/how-to-install-postgresql-on-macos/">this tutorial</a>.</p><h3>3. Generate Database Tables</h3><p>Step 1: Define Table Schema</p><p>Add the following model definition to your prisma/schema.prisma file:</p><pre>// This block of code defines a User model to create user table<br>model User {<br>  id              String    @id @default(cuid()) // primary key with CUID<br>  name            String    @db.VarChar(255) // varchar<br>  phone           String    @unique @db.VarChar(255) // phone must be unique<br>  password        String    @db.VarChar(255)<br>  createdAt       DateTime  @default(now())<br>  updatedAt       DateTime    @updatedAt<br>}</pre><p>Here, we created only 1 table for storing user basic info to login.</p><p>Step 2: Push the Schema to the Database</p><p>Run the following command to apply the schema to your database:</p><pre>npx prisma db push</pre><p>If it executed successful, you’ll see the following message:</p><pre>🚀  Your database is now in sync with your Prisma schema. Done in 67ms</pre><pre>✔ Generated Prisma Client (v6.1.0) to ./node_modules/@prisma/client in 47ms</pre><p>After successfully executed the above command, we can check tables we defined were created in database using prisma studio. To do that, run the following command:</p><pre>npx prisma studio</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g-8ydtHbz9GZr7upsciNXw.png" /></figure><h3>4. Generate the Prisma Client</h3><p>Step 1: Install the Prisma client:</p><pre>yarn add @prisma/client</pre><p>Step 2: Generate the client by running:</p><pre>npx prisma generate</pre><p>We should execute this command every time you make change prisma.schema file.</p><p>Step 3: Create a reusable Prisma client in a new app/lib/prisma.ts file:</p><pre>import {PrismaClient} from &quot;@prisma/client&quot;;<br>// }<br>const globalForPrisma = global as unknown as { prisma: PrismaClient };</pre><pre>// Creating a global instance of PrismaClient or using the existing one<br>export const prisma =<br>    globalForPrisma.prisma ||<br>    new PrismaClient({<br>        log: [&quot;query&quot;],<br>    });<br>// Setting the global Prisma instance if not in production<br>if (process.env.NODE_ENV !== &#39;production&#39;) globalForPrisma.prisma = prisma;</pre><p>This file imports PrismaClient we generated and exports its instance. We can control our database using this instance from anywhere from our project.</p><h3>5. Seed Dummy Data</h3><p>“<strong>Seeding</strong>” refers to adding initial data to the database or populating the database with sample data.</p><p>Step 1: Install bcryptjs</p><p>Install the bcryptjs package to hash passwords:</p><pre>yarn add bcryptjs<br>yarn add -D @types/bcryptjs</pre><p>Step 2: Create seed.ts file in /prisma folder.</p><p>In the prisma folder, create a seed.ts file with the following content:</p><pre>import {PrismaClient} from &#39;@prisma/client&#39;;<br>import bcryptjs from &quot;bcryptjs&quot;;</pre><pre>const prisma = new PrismaClient();<br>// Function to generate a hashed @password<br>const generatePasswordHash = async (password: string) =&gt; {<br>    // generates a random salt. A salt is a random value used in the hashing process to ensure<br>    // that even if two users have the same @password, their hashed passwords will be different.<br>    // The 10 in the function call represents the cost factor, which determines how much<br>    // computational work is needed to compute the hash.<br>    const salt = await bcryptjs.genSalt(10);<br>    return bcryptjs.hash(password, salt);<br>};</pre><pre>const initialUsers = [<br>    {name: &#39;Admin&#39;, phone: &#39;99999999&#39;},<br>    {name: &#39;User&#39;, phone: &#39;88888888&#39;},<br>    {name: &#39;Driver&#39;, phone: &#39;96969696&#39;},<br>];</pre><pre>const seed = async () =&gt; {<br>    // clean up before the seeding (optional)<br>    await prisma.user.deleteMany();</pre><pre>    // you could also use createMany<br>    // but it is not supported for databases<br>    // e.g. SQLite &lt;https://github.com/prisma/prisma/issues/10710&gt;<br>    for (const user of initialUsers) {<br>        const password = await generatePasswordHash(&#39;1q2w3e4&#39;)<br>        await prisma.user.create({<br>            data: {...user, password},<br>        });<br>    }<br>};</pre><pre>seed()<br>    .then(async () =&gt; {<br>        await prisma.$disconnect();<br>    })<br>    .catch(async (e) =&gt; {<br>        console.error(e);<br>        await prisma.$disconnect();<br>        process.exit(1);<br>    });</pre><p>Step 3: Create the Seeder Script</p><p>Add a seed script to package.json:</p><pre>...<br>&quot;scripts&quot;: {<br>    ...<br>    &quot;db-seed&quot;: &quot;prisma db seed&quot; <br>  },<br>  &quot;prisma&quot;: {<br>    &quot;seed&quot;: &quot;ts-node --compiler-options {\\&quot;module\\&quot;:\\&quot;CommonJS\\&quot;} prisma/seed.ts&quot;<br>  },<br>...</pre><p>Finally, run the seed script:</p><pre>yarn db-seed</pre><p>If prisma seed command was successfully executed, we can see the following text.</p><p>After running seed, we can check that we generated initialData in database we defined in seed.ts file.</p><h3>6. Insert and Fetch Data</h3><p>Let’s create user.ts file in /db folder. In a new app/db/user.ts file, define functions to manage user data:</p><pre>// Function to check if a user&#39;s phone is verified<br>import {prisma} from &quot;ospring/app/lib/prisma&quot;;</pre><pre>// Function to find a user by phone in the database<br>export const findUserByPhone = async (phone: string) =&gt; {<br>    return prisma.user.findFirst({<br>        where: {<br>            phone,<br>        },<br>    });<br>};</pre><pre>// Function to find a user by phone in the database<br>export const saveUser = async (phone: string, password: string) =&gt; {<br>    return prisma.user.create({<br>        data: {<br>            name: phone,<br>            phone,<br>            password<br>        },<br>    });<br>};</pre><h3>Final Project Structure</h3><p>You can find the source code for this example <a href="https://github.com/delivus-daas/next-sample-app/tree/PART1_prisma">here</a>.</p><p>In Part2, we’ll cover implementing authentication using <strong>NextAuth</strong>.</p><h3>References:</h3><p><a href="https://nextjs.org/docs/app/api-reference/cli/create-next-app">https://nextjs.org/docs/app/api-reference/cli/create-next-app</a></p><p><a href="https://vercel.com/guides/nextjs-prisma-postgres">https://vercel.com/guides/nextjs-prisma-postgres</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc1b90d60d51" width="1" height="1" alt=""><hr><p><a href="https://medium.com/delivus/how-to-implement-authentication-in-nextjs-15-using-next-auth-prisma-postgres-db-part-1-bc1b90d60d51">How to implement authentication in nextjs 15 using next-auth, prisma, postgres db: Part 1</a> was originally published in <a href="https://medium.com/delivus">딜리버스</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PWA Advanced Service Worker]]></title>
            <link>https://medium.com/delivus/pwa-advanced-service-worker-6459d5fce037?source=rss-23679b72c136------2</link>
            <guid isPermaLink="false">https://medium.com/p/6459d5fce037</guid>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[service-worker]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Chimgee G]]></dc:creator>
            <pubDate>Wed, 08 Jan 2025 07:13:01 GMT</pubDate>
            <atom:updated>2025-01-08T07:13:01.248Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>Service worker is a type of the web worker. It is javascript script file that runs separately from browser’s main thread. Service worker’s main features are the followings.</p><ul><li>intercepting network request</li><li>caching or retrieving resources from the cache</li><li>delivering push messages</li></ul><blockquote><em>If the browser being used doesn’t support background sync, there is no point storing it in the IndexedDB as it cannot be synced later, we directly send the request in this case</em></blockquote><p>Service workers are independent of the application, then</p><ul><li>Service worker cannot access local storage</li><li>Service worker cannot access DOM directly. To communicate with it, service workers call postMessage function.</li><li>Service workers intercept network request, then they only run over HTTPS.</li></ul><p>Service workers depend on 2 APIs.</p><ol><li>Fetch</li><li>Cache(independent from browser cache)</li></ol><h3>Service worker lifecycles</h3><p>Service workers have 3 lifecycles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KNm7s08YqIy0reHuypNJVg.png" /></figure><ol><li>Registration</li></ol><p>Tells your browser where your service worker is located.</p><pre>navigator.serviceWorker.register(&#39;/service-worker.js&#39;, {<br>  scope: &#39;/app/&#39;<br>});</pre><ul><li>navigator.serviceWorker.register(&#39;/service-worker.js&#39;, { scope: &#39;/app/&#39; });</li></ul><p>The scope determines which files the service worker controls,</p><p>2. Installation</p><p>Once the the browser registers a service worker, installation can be attempted. Installation only occurs when service worker is newly registered or updated. A service worker installation triggers an install event. In install event, service worker can perform some tasks such as precaching. So web app can load instantly. The following is how to handle install event.</p><pre>// Listen for install event, set callback <br>self.addEventListener(&#39;install&#39;, function(event) {<br>    // Perform some task<br>});</pre><p>The install event is used to cache assets that are used in the offline mode.</p><pre>self.addEventListener(&#39;install&#39;, (event) =&gt; {<br>  event.waitUntil(<br>    caches.open(&#39;v1&#39;).then((cache) =&gt; {<br>      return cache.addAll([<br>        &#39;./sw-test/&#39;,<br>        &#39;./sw-test/index.html&#39;,<br>        &#39;./sw-test/style.css&#39;,<br>        &#39;./sw-test/app.js&#39;,<br>        &#39;./sw-test/image-list.js&#39;,<br>        &#39;./sw-test/star-wars-logo.jpg&#39;,<br>        &#39;./sw-test/gallery/&#39;,<br>    ...<br>      ]);<br>    })<br>  );<br>});</pre><p>3. Activation</p><p>After service worker’s installation is completed, it activates. But only one service worker is running at any given time. If there is previous service worker, which is running, newly installed service worker will wait until previous one finishes. When the new service worker activates, an activate event is triggered.</p><pre>self.addEventListener(&#39;activate&#39;, function(event) {<br>  // Perform some task<br>});</pre><p>The active event handler is good place to clean up old caches.</p><pre>self.addEventListener(&#39;activate&#39;, (event) =&gt; {<br>  var cacheKeeplist = [&#39;v2&#39;];<br><br>  event.waitUntil(<br>    caches.keys().then((keyList) =&gt; {<br>      return Promise.all(keyList.map((key) =&gt; {<br>        if (cacheKeeplist.indexOf(key) === -1) {<br>          return caches.delete(key);<br>        }<br>      }));<br>    })<br>  );<br>});</pre><p>After a service worker activates, it controls and listens events for all pages that are under its scope.</p><h3>Service worker events</h3><p>install and activate events are triggered when the service worker is installing and activates. Then there are other events that service worker can handle. Service workers won’t receive fetch and push events until it acticates</p><ul><li>Message events</li><li>Fetch events</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9H1t2uiPyOLdEYuK95ILgw.png" /></figure><p>You can handle fetch event of web pages which are within the service workers scope like the following code.</p><pre>self.addEventListener(&#39;fetch&#39;, (event) =&gt; {<br>  event.respondWith(<br>    // magic goes here<br>  );<br>});</pre><ul><li>self.addEventListener(&#39;fetch&#39;, (event) =&gt; { event.respondWith( // magic goes here ); });</li></ul><p>In the fetch event handler, you can check whether response is cached previously in the install event. If it is cached then return cached resource instead of requesting it from the network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zOntPAxz0J6XklLRFnIiLg.png" /></figure><pre>self.addEventListener(&#39;fetch&#39;, (event) =&gt; {<br>  event.respondWith(<br>    caches.match(event.request).then((response) =&gt; {<br>      return response || fetch(event.request);<br>    })<br>  );<br>});</pre><ul><li>Push events</li><li>Sync events</li></ul><h3>Service worker usages</h3><p>Service workers provide the following features.</p><ul><li>Notification API</li><li>Push API</li><li>Background data Synchronization</li></ul><p>Service workers <strong>solve the page loading part</strong> by letting you serve content from a cache. But what about when the page needs to send something to the server? What if users want to close tab or lost internet connection? Background sync helps you to solve this issues. If you implement background sync in your PWA, users requests would be like during the offline mode</p><ol><li>Visit the pwa</li><li>Internet connection is lost</li><li>Send a request</li><li>Close browser or go to the another app</li><li>Internet connection goes online</li><li>Request sent is completed in the background</li></ol><p>To do that register sync for the page</p><pre>// Then later, request a one-off sync:<br>navigator.serviceWorker.ready.then(function(swRegistration) {<br>  return swRegistration.sync.register(&#39;myFirstSync&#39;);<br>});</pre><ul><li>// Then later, request a one-off sync: navigator.serviceWorker.ready.then(function(swRegistration) { return swRegistration.sync.register(&#39;myFirstSync&#39;); });</li></ul><p>Then listen for the event. “myFirstSync” is sync tag name, that should be unique if you want to perform separate syncs.</p><pre>self.addEventListener(&#39;sync&#39;, function(event) {<br>  if (event.tag == &#39;myFirstSync&#39;) {<br>    event.waitUntil(doSomeStuff());<br>  }<br>});</pre><p>“doSomeStuff” is a function that return promise indicating the success/failure of whatever it’s trying to do. If it fulfills, sync will complete, if it fails, another sync will be reserved. Background sync is used for</p><ul><li>photo upload</li><li>Channel Messaging API</li><li>Receives centralized updates to expensive-to-calculates data such as geolocation, so multiple pages can use one set of data</li><li>Hooks for background services</li><li>Custom templating based on certain URL patterns</li><li>Performance enhancements, for example pre-fetching resources that the user is likely to need in the near future, such as the next few pictures in a photo album.</li></ul><h3>Communicate with ClientPage</h3><p>Service cannot directly access to React DOM. Then how to update your user with service worker’s task progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZwLqcZEGlJcJkCuEusSgyw.png" /></figure><p>There are a several ways to communicate service worker with your client page.</p><ol><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API">Broadcast channel API</a> (which is not supported in Safari yet)</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API">Message Channel</a></li><li>Client API</li></ol><p>I will clarify this method in this document.</p><p>In the Service Worker we select the client we want to send the response to with the filter option.</p><p>In the service-worker.ts — somewhere in the service worker</p><pre>self.clients.matchAll(options).then(function (clients) {<br>  if (clients &amp;&amp; clients.length) {<br>    //Respond to last focused tab<br>    clients[0].postMessage({type: &#39;MSG_ID&#39;});<br>  }<br>});in the Service Worker we select the client we want to send the response to with the filter options</pre><ul><li>self.clients.matchAll(options).then(function (clients) { if (clients &amp;&amp; clients.length) { //Respond to last focused tab clients[0].postMessage({type: &#39;MSG_ID&#39;}); } });in the Service Worker we select the client we want to send the response to with the filter options</li></ul><p>On the client-side, we listen to the response of the service worker.</p><p>In the App.tsx — somewhere in the web app</p><pre>if (navigator.serviceWorker.controller) {<br> navigator.serviceWorker.addEventListener(&quot;message&quot;, (event) =&gt; {<br>       console.log(&quot;onMessage&quot;, event.data);<br>       if (event.data &amp;&amp; event.data.type === &quot;MSG_ID&quot;) {<br>         //update ui to inform user<br>         alert(&quot;Upload completed.&quot;);<br>       }<br>  });<br>}</pre><p>Send message from the client to the service worker</p><p>In the App.tsx — somewhere in the web app</p><pre>navigator.serviceWorker.controller.postMessage({<br>  type: &#39;MESSAGE_IDENTIFIER&#39;,<br>});</pre><p>In the service-worker.ts — somewhere in the service worker.</p><pre>self.addEventListener(&#39;message&#39;, (event) =&gt; {<br>  if (event.data &amp;&amp; event.data.type === &#39;MESSAGE_IDENTIFIER&#39;) {<br>    // do something<br>  }<br>});</pre><h3>Whole source — sample github repository</h3><p><a href="https://github.com/Chimaa123/serviceworkertest">https://github.com/Chimaa123/serviceworkertest</a></p><h3>References</h3><p><a href="https://developers.google.com/web/ilt/pwa/introduction-to-service-worker">https://developers.google.com/web/ilt/pwa/introduction-to-service-worker</a></p><p><a href="https://developers.google.com/web/ilt/pwa/tools-for-pwa-developers">https://developers.google.com/web/ilt/pwa/tools-for-pwa-developers</a></p><p><a href="https://dev.to/ruppysuppy/supercharge-your-website-using-pwa-background-sync-1m23">https://dev.to/ruppysuppy/supercharge-your-website-using-pwa-background-sync-1m23</a></p><p><a href="https://developers.google.com/web/updates/2015/12/background-sync">https://developers.google.com/web/updates/2015/12/background-sync</a></p><p><a href="https://web.dev/two-way-communication-guide/">https://web.dev/two-way-communication-guide/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6459d5fce037" width="1" height="1" alt=""><hr><p><a href="https://medium.com/delivus/pwa-advanced-service-worker-6459d5fce037">PWA Advanced Service Worker</a> was originally published in <a href="https://medium.com/delivus">딜리버스</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating PWA with React in Typescript]]></title>
            <link>https://medium.com/delivus/creating-pwa-with-react-in-typescript-2174ac4a89a2?source=rss-23679b72c136------2</link>
            <guid isPermaLink="false">https://medium.com/p/2174ac4a89a2</guid>
            <dc:creator><![CDATA[Chimgee G]]></dc:creator>
            <pubDate>Mon, 11 Oct 2021 07:10:33 GMT</pubDate>
            <atom:updated>2025-03-10T02:24:12.261Z</atom:updated>
            <content:encoded><![CDATA[<p>PWAs are more or less regular websites written using HTML, CSS, and JavaScript. In this article, I will show you how to create a simple PWA using Reactjs in typescript. In the previous article, I introduce about PWA. You can find the previous from <a href="https://medium.com/delivus/pwa-progressive-web-app-c0ca901dd62a">here</a>.</p><h3>PWA checklist</h3><ol><li>runs over HTTPS</li><li>has a manifest.json</li><li>has a serviceworker (javascript .. between web app and network for notifications)</li><li>Responsive, smooth and app like</li><li>Offline working by caching core assets(html, css, js, logos etc)</li><li>Is installable</li></ol><p>PWAs are more or less regular websites written using HTML, CSS, and JavaScript. In this article, I will show you how to create a simple PWA using Reactjs in typescript.</p><h3>PWA checklist</h3><ol><li>runs over HTTPS</li><li>has a manifest.json</li><li>has a serviceworker (javascript .. between web app and network for notifications)</li><li>Responsive, smooth and app like</li><li>Offline working by caching core assets(html, css, js, logos etc)</li><li>Is installable</li></ol><h3>Getting started</h3><blockquote><em>In this document, I assume that you completed to setup your local development environment. If you didn’t, here are some useful links to setup your local environment. You will need to have</em></blockquote><ol><li><a href="https://nodejs.org/en/download/">Nodejs ≥ 10</a></li><li><a href="https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b">npx</a></li></ol><p>You can create a React PWA app using the following PWA custom template CLI in typescript.</p><pre>npx create-react-app my-app-name --template cra-template-pwa-typescript</pre><p>When you create a react application using create-react-app cli, you don’t have to worry about babel and web-pack setup. Because all of them come together.</p><p>Let’s run your web application</p><pre>cd my-app<br>yarn start (npm start)</pre><p>It will start your web server in any browsers automatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Cot7iAHYyMd7DnxZu3Jvg.png" /></figure><h3>Folder structure</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*SyUEUYCfl_2CtkFF6eGi0g.png" /></figure><p><strong>index.tsx</strong></p><p>This is the application start point. React Dom is rendered here.</p><p><strong>package.json</strong></p><p>contains declaration of dependencies of the application.</p><p><strong>yarn.lock</strong></p><p>contains version lists of application dependencies to prevent install newer versions randomly when running yarn or npm command.</p><p><strong>node_modules/</strong></p><p>contains actual application dependencies.</p><p><strong>service-worker.ts</strong></p><p>a JavaScript script that runs in the background, independently from the website itself and make features possible that only in native apps can. Such as background sync, push notifications, offline experiences.</p><p><strong>manifest.json</strong></p><p>includes the name of the PWA, its icon, description etc</p><h3>Audit PWA using Lighthouse tool</h3><p>Let’s check whether PWA we have just created meet the PWA’s checklists. To do that we use Lighthouse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zRNxnRMvgnS7gQ54LipTJw.png" /></figure><p>Lighthouse is a Chrome dev tool to improve web pages quality.</p><ol><li>In Google Chrome, open PWA web server</li><li>Open Chrome DevTools and open Lighthouse tab.</li><li>Select Progressive web app and mobile or desktop</li><li>Click “Generate Report”</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cNHmoVRkFzWOKDPi-HHVKw.png" /></figure><p>Let’s solve those issues one by one.</p><h3>1. Web app manifest or service worker do not meet the installability requirements.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E9CBS7hhU--vEsx_sU05LA.png" /></figure><p>Even if service-worker.tsx file is already created, you need to register a service-worker into the index.tsx file. Change the following line into serviceWorkerRegistration.register();</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NOI5l2YuXzHtM17ZcUt6nQ.png" /></figure><h3>Configure a manifest.json file</h3><ol><li>Register app name in manifest.json</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1LXhE2IF1hTziafsnpkUsw.png" /></figure><ol><li>Save a favicon in the public folder.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*cIVHI6RhXYAFmh72H0Hzxg.png" /></figure><p>An .ico file is just a file that browsers recognize is an icon, and the file contains multiple sizes and colors depths that the computer can scale accordingly.</p><ol><li>Save 192x192 and 512x512 sized logos in he public folder.</li></ol><p>Logo generator: <a href="https://cthedot.de/icongen/">https://cthedot.de/icongen/</a> , <a href="https://realfavicongenerator.net/">https://realfavicongenerator.net</a>, <a href="https://maskable.app/editor">https://maskable.app/editor</a></p><ol><li>Save a maskable icon</li></ol><p>On Android, maskable icon lets developers get rid of the default white background around their icons and use the entire provided space by generating adaptive icons.</p><p>In the PWA, you need to configure a maskable icon by yourself.</p><ol><li>Create your own maskable icon</li><li>You can create a maskable icon from your logo png file using <a href="https://maskable.app/">this tool</a>.</li><li>Register maskable icon into the manifest.json file.</li><li>Icons used in places like the home screen, app launcher, splash screen etc are declared in the manifest.json file. If you create a react app using create-react-app cli, manifest.json file will be created automatically. You can register your maskable icon In the manifest.json file’s icons field. Maskable icon should have purpose field with ‘maskable’ value.</li><li>This is how sample manifest.json file looks like.</li></ol><pre>{ <br>... &quot;icons&quot;: [ <br>     ... {<br>     &quot;src&quot;: &quot;images/maskable_icon_x192.png&quot;, <br>     &quot;type&quot;: &quot;image/png&quot;, <br>     &quot;sizes&quot;: &quot;192x192&quot;, <br>     &quot;purpose&quot;: &quot;maskable&quot; // &lt;-- New property value `&quot;maskable&quot;`.    }, <br>    ... ], <br>... }</pre><h3>Does not register a service worker</h3><ol><li>Copy paste the following code in to the service-</li></ol><pre>const CACHE_NAME = &quot;cache_sample&quot;;<br>const urlsToCache = [&quot;index.html&quot;, &quot;offline.html&quot;];<br>const version = &quot;v0.0.1&quot;;</pre><pre>//install sw at first time<br>//place to cache assets to speed up the loading time of web page<br>self.addEventListener(&quot;install&quot;, (event: any) =&gt; {<br>  console.log(&quot;sw install event&quot;);<br>  event.waitUntil(<br>    caches.open(version + CACHE_NAME).then((cache) =&gt; {<br>      console.log(&quot;opened cache&quot;);<br>      return cache.addAll(urlsToCache);<br>    })<br>  );<br>});</pre><pre>//Activate the sw after install<br>//Place where old caches are cleared<br>self.addEventListener(&quot;activate&quot;, (event: any) =&gt; {<br>  console.log(&quot;sw activate event&quot;);<br>  event.waitUntil(<br>    caches.keys().then((cacheNames) =&gt;<br>      Promise.all(<br>        cacheNames<br>          .filter((cacheName) =&gt; {<br>            return cacheName.indexOf(version) !== 0;<br>          })<br>          .map(function (cachName) {<br>            return caches.delete(cachName);<br>          })<br>      )<br>    )<br>  );<br>});</pre><pre>//listen for requests<br>self.addEventListener(&quot;fetch&quot;, (event: any) =&gt; {<br>  event.respondWith(<br>    caches.match(event.request).then((response) =&gt; {<br>      return response || fetch(event.request);<br>    })<br>  );<br>});</pre><p>Let’s explain above code. Service worker events are handled in this section. You can read further about service worker events from <a href="https://medium.com/delivus/pwa-advanced-service-worker-6459d5fce037">here</a>.</p><ul><li><strong>Install event</strong> only occurs when service worker is newly registered or updated. This is the right place where precaching assets. Above code, we cached index.html and offline.html files.</li><li><strong>Activate event</strong> is triggered when service worker is activated after service worker installation is completed. In the activate events, you can clear old caches.</li><li><strong>Fetch event</strong> is triggered when network request is called. You can check whether response is cached previously in the install event.</li></ul><ol><li>Create offline.html file in the <strong>public/</strong> folder</li></ol><p>This file will be rendered when network status is offline as declared in the service-worker.ts file. You could copy and paste the following content into the offline.html file temporarily. Then you can edit this file how you want.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;title&gt;PWA sample&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;div className=&quot;App&quot;&gt;<br>        &lt;header className=&quot;App-header&quot;&gt;<br>            &lt;img src={logo} className=&quot;App-logo&quot; alt=&quot;logo&quot; /&gt;<br>            &lt;p&gt;<br>                Please go ONLINE<br>            &lt;/p&gt;<br>        &lt;/header&gt;<br>    &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;ƒ</pre><h3>Deploy PWA to AWS amplify</h3><p>There are various ways to deploy PWA to production. But I found one of the easiest way is to use AWS amplify because it helps reactjs app to web with following features such as continuous workflow, monitoring, real time deploying, easy to set a domain.</p><p>PWA should run on HTTPS. Let’s deploy your PWA to the AWS server. In this document we will use AWS amplify service to deploy our PWA.</p><ol><li>Push your project into the version control server. I pushed my source code to the github server. AWS amplify can connect other source control servers such as Bitbucket, Gitlab etc.</li><li>You can find the whole source code from <a href="https://github.com/Chimaa123/pwa-react-sample">here</a>.</li><li>Configure your deployment in the amplify console</li><li>New app⇒ Host web app</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*OvlvrVvL9DnkR-xMwkNgUw.png" /></figure><ol><li>Connect your Github repository to AWS amplify.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wOnxX2DVlKNjZoxr11XlaA.png" /></figure><ol><li>Configure repository and branch of your source code.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QXdDCnOWhweKm5fjJX5VRA.png" /></figure><ol><li>Done!! AWS amplify service makes CI/CD easy. After connecting your PWA’s github repository to AWS amplify, your changes is automatically deployed after every push to your selected branch like the following</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UaPIsiM6T_-Tzt3NJruw6w.png" /></figure><h3>How to install</h3><p>For android</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cfmYhkogneNJnMIQm99S5Q.jpeg" /></figure><p>For ios, safari support “Add to Home Screen.” feature. To install pwa you can tap the ‘Share’ button, scroll down and tap ‘Add to Home Screen.’ Enter the name for the app then tap add. The PWA will show up on your home screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rQeNEZDKnW-8BDvDhEEeJg.png" /></figure><h3>Let’s audit your PWA once more.</h3><p>Finally you can audit your PWA using Google’s audit tool named <a href="https://developers.google.com/web/tools/lighthouse/">Lighthouse tool</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2174ac4a89a2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/delivus/creating-pwa-with-react-in-typescript-2174ac4a89a2">Creating PWA with React in Typescript</a> was originally published in <a href="https://medium.com/delivus">딜리버스</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PWA(Progressive Web App)]]></title>
            <link>https://medium.com/delivus/pwa-progressive-web-app-c0ca901dd62a?source=rss-23679b72c136------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0ca901dd62a</guid>
            <dc:creator><![CDATA[Chimgee G]]></dc:creator>
            <pubDate>Mon, 11 Oct 2021 06:35:37 GMT</pubDate>
            <atom:updated>2021-10-12T01:09:54.143Z</atom:updated>
            <content:encoded><![CDATA[<p>What is progressive web app(pwa)?</p><h3>Purpose of this article</h3><p>In this article we will introduce concept of progressive web apps and its advantage and disadvantage when comparing to web apps and native apps.</p><h3>Contents</h3><ul><li>What is progressive web app(pwa)</li><li>Advantage of progressive web apps (comparing to web apps and native apps)</li><li>What features you can and cannot implement in PWA?</li></ul><h3>What is a Progressive Web App (PWA)</h3><p>Have you ever rejected by app store or play store when updating your mobile application? Are you tired of waiting their approval to update your application? Then progressive web app is a considerable solution to implement and provide your application in real time to your users.</p><p>We are implementing a B2B service. Thus our application is not a commercial application. So we were finding solution which is not reliable to app store and play store, and updates could be in real time without delay. Then we found out about PWA and started to research about it.</p><p>Progressive Web Apps(<strong>PWAs</strong>) are <strong>web applications</strong> that feels like a platform-specific application. They are <strong>fast</strong>, <strong>reliable</strong>, <strong>engaging</strong> and <strong>installable</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*trjDRZjrMc5_V4Pd-EzkIg.png" /></figure><h3>Advantage of Progressive Web Apps</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s6coA28K4AxINBrR68GyFA.png" /></figure><ul><li><strong>Real time update</strong></li></ul><p>PWAs are web applications, then users don’t have to install it from app store or play store and updates are available without any delay.</p><ul><li><strong>Installable (can set home screen icon)</strong></li></ul><p>If users want, they can add PWA into their mobile home screens and reach it by clicking its home screen icon like native applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*F-c-b757fR7YCXrHc9fPHw.png" /></figure><ul><li><strong>Receive push notification</strong></li></ul><p>PWA is able to receive push notifications like native apps even if user closes its web browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*fTwLZV0Sa-hTmUm4WSg4qA.png" /></figure><ul><li><strong>Working offline</strong></li></ul><p>Expect the situation, when you are the middle of some task and your network connection is lost. PWA is more reliable like native applications which users ongoing tasks are restored when network connection is lost and after your device is online it continues this task again.</p><ul><li><strong>Good performance</strong></li></ul><p>PWA doesn’t load its content every time entering to new page like web apps. Because pwa caches its assets using service workers. Service workers run separately from the javascript main thread and caches assets.</p><ul><li><strong>Require low data usage</strong></li></ul><p>PWA caching system make it possible to require a lot less bandwidth than traditional web apps.</p><h3>What features PWA can and cannot do according to internet browser?</h3><ol><li>Safari IOS</li></ol><ul><li>Offline Mode — YES</li><li>Background Sync — NO</li><li>Credentials — NO</li><li>Inter App Sharing — YES</li><li>Local notifications — NO</li><li>Push Messages — YES</li><li>Idle Detections — NO</li><li>Permissions — NO</li><li>Bluetooth — NO</li><li>NFC — NO</li><li>USB — NO</li><li>Serial Port — NO</li><li>Geolocation — YES</li><li>Geofencing — NO</li><li>Device Position — YES</li><li>Device Motion — YES</li><li>Screen orientation &amp; Lock — NO</li><li>Presentation — NO</li><li>Full Screen — NO</li><li>Audio&amp;Video Capture — YES</li><li>Advanced Camera Controls — NO</li><li>Recording Media — YES</li><li>Online State — YES</li><li>Battery Status — NO</li></ul><p>2. Samsung Browser</p><ul><li>Offline Mode — YES</li><li>Background Sync — YES</li><li>Credentials — YES</li><li>Inter App Sharing — YES</li><li>Local notifications — YES</li><li>Push Messages — YES</li><li>Idle Detections — NO</li><li>Permissions — YES</li><li>Bluetooth — YES</li><li>NFC — NO</li><li>USB — YES</li><li>Serial Port — NO</li><li>Geolocation — YES</li><li>Geofencing — NO</li><li>Device Position — YES</li><li>Device Motion — YES</li><li>Screen orientation &amp; Lock — YES</li><li>Presentation — YES</li><li>Full Screen — YES</li><li>Audio&amp;Video Capture — YES</li><li>Advanced Camera Controls — YES</li><li>Recording Media — YES</li><li>Online State — YES</li><li>Battery Status — YES</li></ul><p>As seen the above list (thanks for <a href="https://whatwebcando.today/">https://whatwebcando.today</a>), Apple has more limitation to PWA. But safari is still supporting PWA and new features are becoming available in PWA.</p><p>I hope that you had some understanding about PWA and decided whether you need PWA or not. If you decide to implement your service using PWA in react typescript, then keep following <a href="https://medium.com/delivus/creating-pwa-with-react-in-typescript-2174ac4a89a2">next article</a> to start your own pwa using reactjs.</p><h3>Resources</h3><p><a href="https://www.youtube.com/watch?v=z2JgN6Ae-Bo">https://www.youtube.com/watch?v=z2JgN6Ae-Bo</a></p><p><a href="https://brainhub.eu/library/pwa-vs-native/">https://brainhub.eu/library/pwa-vs-native/</a></p><p><a href="https://whatwebcando.today/">https://whatwebcando.today</a></p><p><a href="https://love2dev.com/pwa/ios/">https://love2dev.com/pwa/ios/</a></p><p><a href="https://www.emergeinteractive.com/insights/detail/enterprise-mobile-app-strategy-progressive-web-native/">https://www.emergeinteractive.com/insights/detail/enterprise-mobile-app-strategy-progressive-web-native/</a></p><p><a href="https://www.coredna.com/blogs/progressive-web-app">https://www.coredna.com/blogs/progressive-web-app</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0ca901dd62a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/delivus/pwa-progressive-web-app-c0ca901dd62a">PWA(Progressive Web App)</a> was originally published in <a href="https://medium.com/delivus">딜리버스</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>