SEO Posts

How to Connect Gatsby to WordPress

Gatsby is a blazing-fast website framework for React. It allows developers to build React-based websites within minutes.

WordPress

WordPress is a free and open-source content management system written in PHP and paired with a MySQL or MariaDB database. Features include a plugin architecture and a template system, referred to within WordPress as Themes.

Integrate Gatsby with WordPress

Install gatsby-source-wordpress package

npm install gatsby-source-wordpress

gatsby-config.js file

add the gatsby config file in the following code

 plugins: [
    ...
    {
        resolve: `gatsby-source-wordpress`,
        options: {
            // Specify the URL of the WordPress source
            baseUrl: `localhost:8888/wordpress`,
            protocol: `http`,
            // Indicates if a site is hosted on WordPress.com
            hostingWPCOM: false,
            // Specify which URL structures to fetch
            includedRoutes: [
              '**/posts',
              '**/tags',
              '**/categories'
            ]
        }
    }

Now connect your gatsby website and Wordpress.

Here is an example of the GraphQL API query

import React from "react"
import { graphql } from "gatsby"
import Layout from "../components/layout"
import SEO from "../components/seo"

export default ({ data }) => {
  return (
      {data.allWordpressPost.edges.map(({ node }) => (
        <div>
          <p>{node.title}</p>
        </div>
      ))}
  )
}
export const pageQuery = graphql`
  query {
    allWordpressPost(sort: { fields: [date] }) {
      edges {
        node {
          title
          excerpt
        }
      }
    }
  }

Hope this helps.

February 28, 20221 minuteVatsal SakariyaVatsal Sakariya
Black Hat SEO Guide - Easy to Understand [2021]

In this chapter, learn about complete black hat SEO and solve your query related to this topic.

Black Hat SEO is a type of SEO technique that google doesn't recommend for sites ranking.

These techniques play with google algorithms and manipulate them for ranking in SERPs.

What is black hat SEO?

Black Hat SEO is totally against search engine guidelines that are used for website higher ranking in google SERP in a very short time.

Google does penalties that site that uses black hat SEO techniques for higher ranking in the search results.

What are black hat SEO techniques?

Black hat SEO techniques are techniques that manipulate google algorithms and play with the searcher's intent.

8 Different types of black hat SEO techniques

1. Use of paid links

Quality-related links drive traffic to websites also get ranking in search results page that's good.

People think if they buy backlinks from others then their websites get a higher ranking in google but paid links are against webmaster guidelines.

So that website never ranks but deindex in google is a high possibility.

So be avoid getting paid links from others that don't relevant to your niche.

If you do SEO for your site or client's website then avoid buying backlinks from others because google rank that site that matches user intent.

If buying links don't have quality content and do not match user intent that also affects your site so be aware when buying paid links.

2. Hidden text in a website

That is another black hat SEO technique that against search engine guidelines.

In white background put white text is a hidden text practice that user can't see but search engine crawler detects them and mark them as unwanted.

Putting text on behind images is also hidden text practice so avoid them getting penalties from Google.

Hidden text google guidelines

  • Don't use a font size as 0
  • Don't put text behind on image
  • Don't use white text for white background

3. Article spinning

Article spinning is a technique that re-writes content synonyms as source information using tools or manually.

Copy article from other sites and do article spinning of copy content and put a new article on website but if you think Google doesn't catch this technique then you are totally wrong because google's algorithm is more powerful than you think.

So be avoid doing article spinning of content and don't paste in websites.

4. Cloaking

Clocking provides different results than users and search engines expected a per search intent that is a violation of webmasters guideline.

Clocking is an old technique of black hat SEO but today as well use this technique by people to manipulate google's algorithm and get the top ranking on SERPs.

But Google can easily catch this technique using powerful algorithms and do penalties that websites that use this types of techniques for ranking.

5. Keyword stuffing

Use the same keyword use several times on one page for most visibility in SERPs it's called keyword stuffing.

Using this content doesn't like natural and user friendly.

Keywords use in articles that should be natural, don't put anywhere that like spamming content.

6. Duplicate content

Duplicate content is that content that is copied from different sources and merges into one content but search engines prefer unique content for the webpage so avoid this technique for better results.

Duplicate content can't rank in google so focus only on unique content.

7. Link Farming

Create a thousand quantity backlinks for ranking in google. But 99% of backlinks are spamming and usually use black hat software like Scrape box, SEnukeTNG to create spamming backlinks.

Backlinks like comment backlinks, social bookmarking backlinks, web profile, article directory, wiki backlinks, gov., and education sites backlinks are automatically created using this software.

If you want to use then there is 4 way to use backlinks

  1. Never use such backlinks on money sites. Use only on short-term micro-niche sites.
  2. Never use such backlinks on your main website
  3. Use it for 2 tier backlinks
  4. You can get brand mentions from selected sites on your main site but without a hyperlink

8. Content Farming

Generated automatic content on websites using activated plugins.

Two disadvantages of auto blogging

  1. Your visitor never become your audience
  2. Rare chances of ranking an auto blogging site on google

Is black hat SEO illegal?

Black hat SEO is not illegal but try to avoid use, which violet search engine guidelines or go against the rules.

If Google catches this technique then will get a penalty or punishment from google in cases your site rank can down or the site can be removed in search engine.

At some time your site can rank using black hat SEO techniques but when googling algorithm catch then suddenly down your site or maybe removed in search engine.

What is a black hat tool?

Black hat tool using this you can do keyword stuffing, link spam, buy unethical link, etc.

Black hat SEO tool list

  • XRumer
  • SeNukeXcr
  • Rankwyz
  • GSA Search Engine Ranker
  • Scrapebox
  • Market Samurai
  • The Best Spinner
  • Tweet Attacks
  • Traffic Booster Pro V3
  • GScraper

Does black hat SEO Still Work?

The answer is yes because some money-making sites use black hat SEO for their website and get ranked in search engines and make money from this.

When google penalty these sites that already make money from this and they don't worry about that.

But most of the sites are made for the long-term future and they worry about that so these techniques are only for short-term results. Don't get long time results using this.

What are black hat backlinks?

Black hat backlinks are types of black hat SEO using keyword stuffing, cloaking, content scraping made backlinks for the website.

These types of backlinks create a negative effect on google SERPs.

Why you shouldn't use black hat SEO?

Create short-time results using this technique.

Poor experience for users using this black hat SEO technique.

The site can deindex or disappear in SERPs.

Reputation and authority of website can be down.

Conclusion:

After that question in your mind is should we use some black hat SEO techniques for the website but the answer is no because black hat SEO is temporary and after some times googles algorithm capt them and down your site from the search engine.

November 11, 20213 minutesMilan GanganiMilan Gangani
Best practices for React JS developer

Today we are going to see best practices for React JS developer

  1. Passing a boolean variables.
  2. Do not define a function within a render
  3. Naming of the components
  4. Use of the Ternary Operators
  5. Don’t Need Curly Braces in string

Passing a boolean variables

Passing boolean variables in to two components.

Not Good

return (
   <Home showTitle={true}/>
); 

Good

return (
   <Home showTitle/>
); 

Do not define a function within a render

Don’t define a function inside render.

Not Good

return (
    <button onClick={() => dispatch(ACTION_TO_SEND_DATA)}>
      Example
    </button>  
)

Good

const submitData = () => dispatch(ACTION_TO_SEND_DATA)
return (
  <button onClick={submitData}>  
    Example 
  </button>  
)

Naming of the components

You can use PascalCase for name of the components and camelCase for name of the instances.

Not Good

import createCard from './CreateCard';
const ReservationItem = <ReservationCard />;

Good

import CreateCard from './CreateCard';
const reservationItem = <ReservationCard />;

Use of the Ternary Operators

Developer how can use ternary operator in React js.

Not Good

const { role } = user;
if(role === 'ADMIN') {
  return <AdminUser />
}else{
  return <NormalUser />
} 

Good

const { role } = user;
return role === 'ADMIN' ? <AdminUser /> : <NormalUser />

Don’t Need Curly Braces in string

When developer passing string props to a children component

Not Good

return(
  <Navbar title={"My Special App"} />
)

Good

return(
<Navbar title="My Special App" />  
)

Hope this helps for React js developer

November 06, 20213 minutesVatsal SakariyaVatsal Sakariya
White Hat SEO: Complete Informative Guide

White hat SEO is the ethical and useful proven technique suggested by search engines for a higher ranking in SERP and content strategies are based on user experience rather than spammy techniques.

In this blog post, we will discuss a complete guide of white hat SEO techniques. This is a complete information guide and I hope this guide solved your queries related to white hat SEO.

Read this post to the end to solve your query about any White Hat SEO-related topics. I am sure if you read this post to the end so your query will be solved.

So let's get started to solve user's queries with proven techniques:

What are the strategies of White Hat SEO?

1. Provide valuable content to a user

Generally, people blog posts use to gain organic traffic to a website, and also this works as lead generation. Create the content on what people are looking for and your content should be relevant to this particular topic.

If your content is relevant and authoritative so other people use it as a reference means you can backlinks from this type of user.

2. Satisfy User Intent

Satisfying user intent should be your primary goal. If users type query "SEO Guide" that means they want a result-related SEO guide, not other things. So, user intent is based on the user's query.

Generally user intent is four types: Navigational, Transaction, Commercial, Informational.

Here are some examples based on user intent, if the user search query "SEO Tutorial" means they looking for information about a particular topic so this is the informational user intent.

If user search "SEO services" means they want/give to SEO service so it is navigational user intent.

If a user searches "Top 5 strategies of SEO" it means they want to know about SEO strategies so it's commercial user intent.

If a user searches "Buy Clothes" it means they want to buy clothes so it's transactional user intent.

Strategies for satisfying user intent

  • Know your buyer's persona
  • What are they looking for
  • Optimize content with specific keywords
  • Use videos and images in the content

3. Make website mobile-friendly

Almost 52% of traffic coming to websites using mobile phones means your website should be mobile friendly are important. If your site doesn't mobile-friendly then Google can not index your site into SERP.

You can check your site is mobile-friendly or not using Google’s mobile-friendly test tool.

How many White Hat SEO techniques are there?

Why do we use white hat SEO techniques? some of the questions in your mind are related to this topic so today we discuss that topic and solve your query.

1. Prioritize to Quality Content

In Modern-day SEO content is king. So we mostly focus on content that users can easily understand and react on content. While writing content your focus should be on users not on search engines because you write content for users, not for search engines.

If users like your content and spend time then automatically your content ranks in the search engine so focus only on the best user intent content.

Some factors for Quality content,

  • Length of your content
  • Topic for content writing
  • Keyword distribution on the whole topic
  • Internal links & External links

2. Content related keyword

While writing blog posts you must know that content and keyword should be related.

Select 1 primary keyword and 3 to 4 secondary keywords for content. Don't stick only primary keyword because if the primary keyword doesn't rank in the search engine then possibility secondary keyword may be ranked in the search engine so select secondary keyword while writing content.

Each of your keywords should be related to content type.

3. Keyword-rich in the page title and meta-data

Keyword in page title and meta-data is mandatory so search engines easily understand the content type and rank in search engine.

Some people ignore this thing but it's a direct signal to search engines for ranking your page.

4. Simple website navigation

Simple website navigation boosts your organic search engine ranking also users can easily find your website pages.

If your website has a simple navigation structure then users can spend more time on your website it means your site is up the side in search engines easily because the user experience is most important to rank in search engines.

5. Fast page loading speed

Fast page loading speed is important to a higher ranking in search engines.

Core web vitals are new for the loading page speed factor so you should consider them while managing your page.

Using this increase your page loading speed:

  1. Minified Javascript and CSS file
  2. Cashed Javascript and CSS files
  3. Compressed images
  4. Reduce redirects from the website

6. Priority to user experience

Priority to user experience while designing your page and content.

Some signal to make the best user experience

  1. Decrease bounce rate
  2. Simple navigation structure
  3. Use images and video in content
  4. Use Schema structure
  5. Only use White Hat SEO techniques
  6. Paragraph should be maximum 3 to 4 line

7. Use schema markup

Schema markup is not direct ranking factors for search engine but using this make better user experience.

If you use schema on your page so google can understand and show some of the points of your pages as the content type for attracting users to your page.

So, recommended is to use schema for your page you want to rank in search engine.

8. Quality link building for webpage

Link building is an off-page SEO strategy. Quality content & link this is an important factor who want a higher rank in search engines.

Get quality link building from high domain authority sites compare to your site.

Why is White Hat SEO important?

Because without white hat SEO you never ranked in search engines.

Sites exist in search engines because of white hat SEO, no black hat or gray hat SEO techniques.

Importance of White Hat SEO

  1. Improve your search rankings in search engine
  2. Save money because you don't go for paid advertisements
  3. Produce quality content
  4. Your site should always be prepared for algorithm updates

Should you always use White Hat SEO?

Yes, obviously you should always use white hat SEO because no chance of deindexing your site in search engines.

If you use black hat SEO techniques then a high chance of your site being deindexed in search engines.

SEO experts always tell use white hat SEO techniques to your site for long-lasting highly results.

Is White Hat SEO legal?

Yes, Always without any doubt white hat SEO is legal and you should always use white hat SEO techniques for your site to better ranking in search engines.

If you have any doubt or queries related to white hat SEO then you read this complete post for solved your query or doubt.

How to do White Hat SEO?

Following steps for white hat SEO:

  1. Crete attractive design for user
  2. Don't copy the content of other sites
  3. Technical site audit for check issue or not
  4. On-page SEO site audit for check issue or not
  5. Backlink audit for quality check
  6. Follow SEO guidelines
  7. Use schema markup
  8. Update content from time to time

Conclusion:

White Hat SEO: complete informative guide in this topic we discussed complete white hat SEO importance, strategies, advantages, and try to solve queries related to this topic. I hope this guide may be useful for you.

October 17, 20213 minutesMilan GanganiMilan Gangani
On-Page SEO : The Ultimate Guide[2021]

On-page are SEO types are used for ranking your webpage in google at no.1 position to get more traffic. That can take time but it's processed for a one-time setup than organically site rank in google and you get high-quality results.

Here you can get the ultimate guide about on-page SEO and you can apply this process to get results as you expect.

Factors for On-Page SEO

There are some factors that affect while process of on-page SEO.

So, let's get started,

1. Title

The title is the most important factor for the rank website in google. A page title should be attractive for the user if the user doesn't interest in your title then the user never read your blog post.

The title length should be 50 - 60 characters. Google can cut down longer versions of the title and your title doesn't see in google as you expect.

Here is the list for titles:

  • Use a keyword in the title
  • A Longer version of the keyword used in the title
  • CTA - call to action word use
  • Don't use stop words
  • Use your brand name in the title

2. Metatags

Metatags are also the most important factor for ranking. Metatags consist of a meta title, meta description, meta keyword, etc.

The length of the meta description should be generally 155 to 160 characters.

Metatags represent your whole blog in short. It should be attractive for user expectations.

Google can change your meta description and meta title user's query related but write meta description is required. And it should be relevant to your blog post.

3. SSL Certificate

Users can trust an only secure site if your site has no SSL certificate then it shows not secure so, user cannot trust on this site and don't provide information to this site.

Your site not should be HTTP but should be HTTPS using this gets user trust belongs to your site easily.

Example:

http://infyom.com/ - without an SSL certificate

https://infyom.com/ - with SSL certificate

4. Responsive Website

The website should be mobile-friendliness if not then google can not index a particular webpage or site.

5. Navigation

Navigation of your website is should be easy for users so users can spend more time on your site.

Users can easily go from one page to another page using simple navigation.

You can use a breadcrumbs snippet for easy navigation.

6. Page Loading Speed

Core web vitals plays an important role in page loading speed. Low page loading speed means users can more time spent on a website.

Key factors:

  • Images compression
  • Compress javascript and CSS files
  • Cashed javascript and CSS files
  • Light theme

7. Text Visibility

Another important factor is text visibility. Text on your site should be visible to the user. Not used word to white text in the white background is not visible for the user.

8. CTA - Call to Action

Use call-to-action words in your content for getting to user interaction with your content.

Ex. Buy Now, 2 Days left only, Create an account, Free e-book, Explore, Join now, Discover, etc. all are call-to-action words that use in your content to increase user interaction with your content.

9. Img alt text

Always use alt text for every image that is in content. Alt text should be relevant to your image.

Don't use repeat alt text in the same content.

10. Internal Linking

Your site pages should be interlinking with each other for easy navigation. Google can easily understand your site structure if you use interlinking of all pages with each other.

Google can easily crawl them and indexed them in SERP. Using this users can spend more time on your website and you can get a rank in google.

11. External linking

You can do link to high domain authority web pages on your page. This is also a ranking factor in on-page SEO.

Not limit to external linking to your web pages.

12. URL Structure

Use an easy URL structure for your web pages. Don't use a long-form of URL structure.

Conclusion:

All factors are important in on-page SEO points of view so, follow these steps to get a higher ranking in google.

September 16, 20212 minutesMilan GanganiMilan Gangani
What is HTML <meta> Tag?

This blog gives information and different elements of the meta tag.

A meta is a type of HTML tag.

meta is the only exit in HTML5. They are usually on the "head" of the page.

It provides search engines with information about a website page. Metadata will not be displayed on the page, but the machine is parsable.

The meta element is used to specify page description, keywords, author, and other metadata.

HTML introduced a method to let web designers take control over the viewport (the user's visible area of a web page) through the meta tag.

Note: Metadata is always passing as name/value pairs.

meta keywords

Define keywords for search engines

<meta name="keywords" content="HTML5 meta tag, meta tag important for SEO, meta description, meta keywords, meta author, meta title">

meta description

Define a description of your webpage.

Description Meta tags are coming up that contain web passage information. The description meta tag is the most important tag, your application will be ranked on your page by search engines. The description has relationships between 150 and 160 characters

<meta name="description" content="Meta tag provides search engines with information about a website page.">

Author Name

Author attribute specifies the author of the webpage.

<meta name="author" content="Payal Pansuriya">

http-equiv attribute

HTML meta refresh tag refreshes the page as you mention the time in the content.

<meta http-equiv="refresh" content="10">

August 12, 20212 minutesPayal PansuriyaPayal Pansuriya
5 Easy ways to create a Backlink for Website

Today I’m going to show you 5 easy ways to create a backlink for a website. If you do apply this method I'm sure to get a quality high-domain authorities website backlink.

At this time, all people want their website to rank 1st in google ranking.

If you want to rank your website in google 1st, create a backlink from a high authority site.

So let’s get started with 5 easy ways to create a backlink for a website.

1. Article Submission

What is article submission?

Article submission is the process to submit your article to high-quality websites or directories to improve SEO ranking and get traffic to websites.

Some free sites are available for submitting an article.

Article submission is one of the easy ways to create backlinks for a website.

Why Article submission important from a backlink point of view?

Article submission is an effective off-page SEO technique.

Using Article submission you can get quality backlinks from high domain authorities websites which use to get traffic to your website and improve SEO ranking.

How to submit an article to a free article submission site?

  • Check article submission site DA & PA.
  • Register on the article submission site.
  • Choose the category of your article.
  • Include your article or website link in the author’s description box. It’s the most important step.
  • Submit your article
  • Check if your article is published or not.

Here is some site to submit Free Article

  • Articlebiz

  • Articles Factory

  • Tumblr

  • Quora

  • Apsense

2. Quora Answering

What is Quora Answering?

Quora answering is the site where users can ask questions related to their queries. And people can answer a user's query in quora.

What is the DA of quora?

  • DA: 93

Why is Quora useful for backlinks?

People can answer user’s queries in quora. And put their website link or article post link.

It’s a type of backlink. When users click on that link they redirect to your site.

Quora is an easy way to create a backlink for your website.

Using Quora you can create a high-quality backlink.

Quora backlink is also affecting traffic to your website means increased traffic to your website and improve your SEO ranking using create a backlink from quora.

Guideline to create a backlink on quora

  • Do not create a backlink
  • First some answers to user’s queries
  • The recommended way is to answer 5 user’s queries and create links to only a maximum of two of them.
  • If you create all answers with your link then quora can ban you.

How to create a backlink from quora?

  • Create an account on quora
  • Answer user’s queries
  • Create a link to your article.
  • It’s a Nofollow backlink for your website.

All quora backlink is nofollow means It’s used to increase traffic for your website but google crawler can not read backlink because it’s nofollow.

3. Social Bookmarking

What is social bookmarking?

Social bookmarking is sites where a user submits their blog post, article, videos, etc.

Why use social bookmarking for SMM?

Social bookmarking sites where social media marketing managers find posts to their relevant topic. It’s Important to reach our posts through social media to more people and get traffic from them.

How to use a social bookmarking site to create backlinks?

  • Create an account
  • Submit your site
  • Create a backlink

Here are some sites of social bookmarking

  • Reddit

  • Scoop it

  • Metafilter

  • Solo

  • Bookmarktou

It’s an easy way to create a backlink for your website. In social bookmarking sites some backlinks are dofollow and some backlinks are nofollow.

4. Directory Submission

What is directory submission?

Directory submission where you can submit your site URL and details about your website to increase link building for your site.

A web directory is a kind of a website that has some categories, sub-categories. You can submit your site to a category of your niche.

Why is direct submission important for link building?

Using directory submission you can create high-quality backlinks from some high-domain authorities. It’s useful to get more traffic to your website and improve SEO ranking.

Types of Web Directory

  • Paid and featured listing
  • Regular link with reciprocal link
  • Free and regular listing

How to use the Directory Submission site to create backlinks?

  • Create an account
  • Select a free and regular listing option
  • Submit detail about your website
  • Create backlinks

Here are some sites of social bookmarking

  • Somuch

  • Marketinginternetdirectory

  • Prolinkdirectory

  • Bedwan

  • Livepopular

5. Ping Submission

Ping Submission is a mechanism of sending auto generated notifications to google spider.

It is one type of SEO tool. Where you can submit your blog post or website to get backlinks.

What are the benefits of Ping submission?

  • Improve SEO ranking
  • Useful for site indexing
  • Easy ways to create backlinks
  • Also, use for improving search engine result pages

How to get backlinks using ping submission?

  • Create an account on the ping submission site
  • Submit a blog post to the relevant category
  • Get a backlink
  • Not submit more than 3 same URLs on one ping submission site

Ping Submission Site

  • Pingomatic

  • Pingmylinks

  • Pingmyblog

  • Pingler

  • Ping

Conclusion:

In this topic 5 easy ways to create a backlink for a website, if you read the whole blog post you have an answer on how to create backlinks. I hope your problem will be solved on this topic.

July 24, 20214 minutesMilan GanganiMilan Gangani
How to make a Progressive Web App

What is a PWA?

A Progressive Web App (PWA) is a hybrid of a regular web page and a mobile application. A PWA combines features offered by most modern browsers with the benefits of the mobile experience. They are built using standard web technologies, including HTML, CSS, and JavaScript. The functionalities include working offline, push notifications, and device hardware access and enabling creating user experiences similar to native applications.

How to make a PWA

Following Below steps

  • Create an app manifest.json file
  • Add it to your base HTML template
  • Create the service worker
  • Serve the service worker on the root of the scope you used in the manifest
  • Add a block to your base HTML template file
  • Site deploy in your server

Create an App Manifest

  • Add the following information in 'manifest.json'
 {
    name: `Name`,
    short_name: `Sort name`,
    start_url: `/`,
    display: `standalone`,
    icon:  `Favicon icon`,
    icons: [
       {
        "src": "icon by size",
        "sizes": "144x144",
        "type": "image/png",
        "purpose": "any"
      },
      {
        "src": "icon by size",
        "sizes": "192x192",
        "type": "image/png",
        "purpose": "maskable"
      },
      {
        "src": "icon by size",
        "sizes": "512x512",
        "type": "image/png",
        "purpose": "maskable"
      }
    ],
  theme_color: `Theme color`,
  background_color: `Background color`,
  ]
 }
  • Manifest.json file in add this type of code including name, short_name, start_url, display, icon, icons, theme_color, background_color.

Add the Manifest to Your Base HTML Template

  • Add the following line in yore 'index' file

Create offline.html as an Alias to index.html

By default, the service worker code below will render /offline.html instead of any resource it can't fetch while offline. Create a file at /offline.html to give your user a more helpful error message, explaining that this data isn't cached and the user is offline.

Create a Service Worker

  • Create one file in yore root (sw.js)
  • Link the sw.js file in the body tag

We have created some pages like

  1. Home page (/)
  2. Blog page (/blog)
  3. Contact information (/contact)
  4. Resume (/resume)
  5. offline.html
  • Add the code in your sw.js file
self.addEventListener("install", function(event) {
   event.waitUntil(preLoad());
});

 var preLoad = function(){
  return caches.open("offline").then(function(cache) {
    return cache.addAll(["/blog/", "/blog", "/", "/contact", 
 "/resume", "/offline.html"]);
    });
 };

 self.addEventListener("fetch", function(event) { event.respondWith(checkResponse(event.request).catch(function() 
  {
     return returnFromCache(event.request);
   }));
   event.waitUntil(addToCache(event.request));
  });

  var checkResponse = function(request){
   return new Promise(function(fulfill, reject) {
     fetch(request).then(function(response){
       if(response.status !== 404) {
         fulfill(response);
       } else {
         reject();
       }
     }, reject);
   });
  };

  var addToCache = function(request){
   return caches.open("offline").then(function (cache) {
     return fetch(request).then(function (response) {
       console.log(response.url + " was cached");
       return cache.put(request, response);
     });
   });
  };

  var returnFromCache = function(request){
   return caches.open("offline").then(function (cache) {
     return cache.match(request).then(function (matching) {
      if(!matching || matching.status == 404) {
        return cache.match("offline.html");
      } else {
        return matching;
      }
     });
   });
  };
  • Servicer worker file add your body tag

load the service worker file in

<script>
   if (!navigator.serviceWorker.controller) {
   navigator.serviceWorker.register("/sw.js").then(function(reg) {
         console.log("Service worker has been registered for scope: " + reg.scope);
     });
 }
 </script>

Last step

  • Deploy code in yore live site
  • Create lighthouse report and check PWA
July 28, 20214 minutesVatsal SakariyaVatsal Sakariya