New Self New Life
No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
New Self New Life
No Result
View All Result
Home Softwares

GetStaticProps vs GetServerSideProps: Next JS Data Fetching

by admin
3 years ago
in Softwares
GetStaticProps vs GetServerSideProps: Next JS Data Fetching
Share on FacebookShare on Twitter


Whats up buddies, NextJS gives a number of completely different information fetching methods. At the moment we’re going to educate you about GetStaticProps vs GetServerSideProps: Subsequent JS Information Fetching. So let’s start.

Subsequent.JS is a device employed primarily to construct server-side rendered web sites that generate the HTML dynamically via a server throughout each occasion of receiving a brand new request.

Information fetching in Subsequent.js permits you to render your content material in several methods, relying in your utility’s use case. These embody pre-rendering with Server-side Rendering or Static Era, and updating or creating content material at runtime with Incremental Static Regeneration.

So let’s begin with GetStaticProps.

GetStaticProps

This methodology is primarily used inside a web page to fetch information at construct time.

As soon as the app is constructed, it would refuse to refresh the information until the time one other construct has been run.

The benefit of utilizing GetStaticProps is that it lets the web page be statically generated. In consequence, out of all of the accessible information fetching strategies, GetStaticProps generates the quickest load instances.

As the information is rendered earlier than it reaches the shopper, the search engine optimisation of the web page improves by leaps and bounds.

It’s best to use getStaticProps if:

The information required to render the web page is offered at construct time forward of a consumer’s request

The information comes from a headless CMS

The web page have to be pre-rendered (for search engine optimisation) and be very quick — getStaticProps generates HTML and JSON recordsdata, each of which might be cached by a CDN for efficiency

The information might be publicly cached (not user-specific). This situation might be bypassed in sure particular conditions through the use of a Middleware to rewrite the trail.

Instance:- how one can fetch a listing of articles from a CMS.

// articles will probably be populated at construct time by getStaticProps()
operate Article({ articles }) {
  return (
    <ul>
      {articles.map((article) => (
        <li>{article.title}</li>
      ))}
    </ul>
  )
}

// This operate will get known as at construct time on server-side.
// It will not be known as on client-side, so you possibly can even do
// direct database queries.
export async operate getStaticProps() {
  // Name an exterior API endpoint to get articles.
  // You should utilize any information fetching library
  const res = await fetch('https://.../articles')
  const articles = await res.json()

  // By returning { articles: { articles } }, the Artical element
  // will obtain `articles` as a prop at construct time
  return {
    props: {
      articles,
    },
  }
}

export default Article

Runs on each request in improvement

In improvement (subsequent dev), getStaticProps will probably be known as on each request.

GetServerSideProps

This methodology is primarily used to fetch information for each occasion {that a} consumer points a request to the web page.

It fetches the information first earlier than sending the web page to the shopper. Ought to the shopper occur to concern a subsequent request, the information is fetched once more.

Utilizing GetServerSideProps permits you to enhance your search engine optimisation as on this methodology the information is rendered earlier than it reaches the shopper.

As the information is refreshed each time the consumer hundreds the web page, they’ll view the up to date info always.

When ought to I take advantage of getServerSideProps

It’s best to use getServerSideProps provided that it is advisable render a web page whose information have to be fetched on the requested time. Pages utilizing getServerSideProps will probably be server-side rendered at request time and solely be cached if cache-control headers are configured.

Instance:- fetch information at request time and pre-render the outcome.

operate Web page({ information }) {
  // Render information...
}

// This will get known as on each request
export async operate getServerSideProps() {
  // Fetch information from exterior API
  const res = await fetch(`https://.../information`)
  const information = await res.json()

  // Cross information to the web page through props
  return { props: { information } }
}

export default Web page

If you don’t want to render the information through the request, then you need to contemplate fetching information on the client-side or getStaticProps methodology.

Comfortable Coding !!! ?

author-thumb

Rahul Chaudhary
2 Badges

28 June 2022



Source link

Tags: DataFetchingGetServerSidePropsGetStaticProps
Previous Post

NASA takes a step towards putting humans back on the Moon with CAPSTONE launch

Next Post

Best 4th of July Home Sales: $3 West Elm Deals & 70% Off Pottery Barn

Related Posts

Unlocking the Future of Finance
Softwares

Unlocking the Future of Finance

by admin
May 8, 2025
Address bar tweaks – Vivaldi Browser snapshot 3683.4
Softwares

Address bar tweaks – Vivaldi Browser snapshot 3683.4

by admin
May 7, 2025
A faster, sleeker JavaScript experience
Softwares

A faster, sleeker JavaScript experience

by admin
May 10, 2025
How WordPress Agencies Can Improve Site Building Efficiency — Speckyboy
Softwares

How WordPress Agencies Can Improve Site Building Efficiency — Speckyboy

by admin
May 6, 2025
Grand Theft Auto VI delayed again, this time until May 2026
Softwares

Grand Theft Auto VI delayed again, this time until May 2026

by admin
May 5, 2025
Next Post
Best 4th of July Home Sales: $3 West Elm Deals & 70% Off Pottery Barn

Best 4th of July Home Sales: $3 West Elm Deals & 70% Off Pottery Barn

Study finds toxicity in the open-source community varies from other internet forums

Study finds toxicity in the open-source community varies from other internet forums

  • Trending
  • Comments
  • Latest
Cameron Monaghan Discusses Erotic Thriller

Cameron Monaghan Discusses Erotic Thriller

January 13, 2022
Doctor Strange: 12 Best Comic Issues Of The 1990s

Doctor Strange: 12 Best Comic Issues Of The 1990s

December 11, 2021
Phantom Parade Gets Opening Movie, Cast Announced

Phantom Parade Gets Opening Movie, Cast Announced

March 8, 2022
Anant Ambani wedding: Celebs, wealthy elite attend lavish billionaire festivities – National

Anant Ambani wedding: Celebs, wealthy elite attend lavish billionaire festivities – National

March 1, 2024
Guide for Odoo Website Razorpay Checkout Payment Acquirer

Guide for Odoo Website Razorpay Checkout Payment Acquirer

January 6, 2023
What Are the Best User Provisioning Practices for SaaS Apps

What Are the Best User Provisioning Practices for SaaS Apps

September 9, 2022
10 Content Marketing Statistics Every Marketer Should Know In 2022 [Infographic]

10 Content Marketing Statistics Every Marketer Should Know In 2022 [Infographic]

May 6, 2022
The Definitive 30-Step Basic SEO Checklist for 2022

The Definitive 30-Step Basic SEO Checklist for 2022

January 3, 2022
Study Uncovers the One Thing That Cuts Through Climate Apathy: Loss

Study Uncovers the One Thing That Cuts Through Climate Apathy: Loss

May 10, 2025
Millennium Docs Against Gravity Expands Industry Program

Millennium Docs Against Gravity Expands Industry Program

May 10, 2025
Billy Ray Cyrus shares rare photo with daughter Miley amid rumoured family rift

Billy Ray Cyrus shares rare photo with daughter Miley amid rumoured family rift

May 10, 2025
Galantis Is Throwing a Midsommar-Themed Concert at Red Rocks

Galantis Is Throwing a Midsommar-Themed Concert at Red Rocks

May 10, 2025
Startups, Stop Chasing Only Clicks: Why Brand Building (and Out-Of-Home Ads) Deserves Your Attention from Day One

Startups, Stop Chasing Only Clicks: Why Brand Building (and Out-Of-Home Ads) Deserves Your Attention from Day One

May 10, 2025
Bill Gates says he will give away almost all of his money over next 20 years

Bill Gates says he will give away almost all of his money over next 20 years

May 9, 2025
Here’s How You Can Win a $500 Prepaid Visa Gift Card

Here’s How You Can Win a $500 Prepaid Visa Gift Card

May 9, 2025
Ben Affleck Embraces Latina Love Post-Jennifer Lopez Divorce

Ben Affleck Embraces Latina Love Post-Jennifer Lopez Divorce

May 9, 2025
New Self New Life

Your source for entertainment news, celebrities, celebrity news, and Music, Cinema, Digital Lifestyle and Social Media and More !

Categories

  • Celebrity
  • Cinema
  • Devices
  • Digital Lifestyle
  • Entertainment
  • Music
  • Social Media
  • Softwares
  • Uncategorized

Recent Posts

  • Study Uncovers the One Thing That Cuts Through Climate Apathy: Loss
  • Millennium Docs Against Gravity Expands Industry Program
  • Billy Ray Cyrus shares rare photo with daughter Miley amid rumoured family rift
  • Home
  • Disclaimer
  • DMCA
  • Privacy Policy
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites. slotsfree  creator solana token

No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites.

fafafa slot