NextJs in 7 Minutes 🔥

CodeWithHarry
13 Nov 202106:56

Summary

TLDRNext.js, a powerful React framework by Vercel, is renowned for its SEO-friendly capabilities, utilized by major companies like Netflix and GitHub. Unlike typical React apps, which render on the client side and face SEO challenges, Next.js employs page building strategies like Static Site Generation and Server Side Rendering to deliver fast, static content suitable for search and social media bots. With features like file-based routing and built-in utilities for image optimization, Next.js enhances the React experience, ensuring high performance and user satisfaction. The latest version, featuring a Rust compiler, has further increased its popularity for its speed and efficiency.

Takeaways

  • 🌟 NextJS is a powerful React framework developed and maintained by Vercel, known for its SEO-friendly capabilities.
  • 🚀 Prominent companies like Netflix, GitHub, Uber, and Starbucks utilize NextJS for their web development needs.
  • 🔍 Traditional React applications are client-side rendered, which can hinder SEO due to the reliance on JavaScript for content rendering.
  • 🤖 Search and social media bots struggle to index client-side rendered content, affecting the visibility and ranking of websites.
  • 🛠 NextJS addresses these issues by implementing server-side rendering and static site generation for improved SEO and faster content delivery.
  • 📝 NextJS introduces file-based routing, simplifying URL structure and reducing the need for external routing libraries like React Router DOM.
  • 🖼️ Built-in utilities in NextJS enhance image optimization and content structuring, streamlining the development process.
  • 🏗️ Static Site Generation (SSG) in NextJS converts dynamic sites into static ones, improving load times and making content accessible to bots.
  • 🔄 Server Side Rendering (SSR) allows for dynamic data fetching on the server, providing up-to-date content while maintaining the perception of static HTML to users and bots.
  • ⏱️ Using SSR, websites can maintain fast first contextual paint times, improving user experience and aligning with core web vitals.
  • 🔄 The 'revalidate' key in getStaticProps enables periodic content updates on static sites, striking a balance between static generation and dynamic content refresh.
  • 🔧 The latest version of NextJS includes a Rust compiler, enhancing performance and making it a preferred choice among developers.

Q & A

  • What is NextJS and who maintains it?

    -NextJS is a popular React framework optimized for building SEO-friendly websites. It is built and maintained by Vercel.

  • Why do companies like Netflix, GitHub, Uber, and Starbucks use NextJS?

    -These companies use NextJS because it enhances the capabilities of React by providing server-side rendering and static site generation, improving SEO and user experience.

  • What is the main issue with typical React applications regarding SEO?

    -Typical React applications are client-side rendered, which means search engine bots cannot index the content properly, leading to poor SEO performance.

  • How does NextJS address the issue of social media bot previews?

    -NextJS allows for server-side rendering or static site generation, enabling social media bots to read the content of the page and generate accurate previews.

  • What is the significance of First Contextual Paint in the context of NextJS?

    -First Contextual Paint is a core web vital that measures when the main content of a page is visible to the user. NextJS improves this metric by reducing the time it takes for content to be rendered, enhancing user experience.

  • Can you explain the concept of file-based routing in NextJS?

    -File-based routing in NextJS allows developers to create pages by simply creating files in the 'pages' directory. The URL structure is automatically generated based on the filenames, eliminating the need for an external router.

  • What is the role of the getStaticProps() method in NextJS?

    -The getStaticProps() method is used in static site generation, where it fetches data that will be passed to the page as props. This data is then used to generate static pages that can be cached via a CDN for fast delivery.

  • How does Server Side Rendering (SSR) differ from Static Site Generation in NextJS?

    -SSR generates pages on the server each time they are requested, ensuring that users receive up-to-date content. In contrast, Static Site Generation creates pages ahead of time, which is ideal for content that does not change frequently.

  • What is the purpose of the revalidate key in getStaticProps()?

    -The revalidate key in getStaticProps() allows for periodic regeneration of static pages, providing a balance between the speed of static sites and the freshness of content.

  • What new feature does the latest version of NextJS offer?

    -The latest version of NextJS includes a Rust compiler, which significantly improves the framework's performance.

  • Why is NextJS considered an enhancement to the powers of React?

    -NextJS enhances React by providing solutions for SEO, content previews, and improved performance through server-side rendering, static site generation, and built-in features like file-based routing and image optimization.

Outlines

00:00

🌐 NextJS: The React Framework for SEO and Performance

NextJS is a highly praised React framework developed by Vercel. It is favored by major companies like Netflix, GitHub, Uber, and Starbucks for creating SEO-friendly websites. Traditional React applications render on the client side, which can lead to SEO challenges as search engine bots struggle to index JavaScript-driven content. This can also affect social media previews, as bots cannot execute JavaScript to generate previews. NextJS addresses these issues by allowing content to be pre-rendered, either server-side or through CDN caching, enhancing SEO and user experience. It introduces file-based routing, simplifying URL structure management, and offers built-in utilities for image optimization and content structuring. NextJS also supports static site generation and server-side rendering, catering to both static and dynamic content needs. Static site generation converts dynamic content into a static site for fast delivery and easy indexing, while server-side rendering ensures dynamic content is served with optimal performance.

05:03

🚀 Enhancing User Experience with NextJS's Page Building Strategies

NextJS further improves user experience and content accessibility through its page building strategies. It allows for both static site generation and server-side rendering, ensuring that content is readily available and up-to-date. Static site generation is ideal for content that doesn't change frequently, while server-side rendering is better suited for dynamic content. NextJS also introduces a hybrid approach where content can be revalidated periodically using the `revalidate` key in `getStaticProps`. This strategy ensures that static sites can be refreshed with new content at specified intervals. The new version of NextJS, which is free and open-source, includes a Rust compiler for enhanced performance. This makes NextJS an even more attractive choice for developers looking to leverage the power of React with improved SEO and performance.

Mindmap

Keywords

💡NextJS

NextJS is a React framework developed by Vercel, designed to facilitate the creation of SEO-friendly websites. It is integral to the video's theme as it discusses the benefits of using NextJS over a typical React application for better search engine optimization (SEO) and user experience. The script mentions that companies like Netflix, GitHub, Uber, and Starbucks use NextJS, highlighting its industry adoption.

💡SEO

SEO, or Search Engine Optimization, is the process of improving a website's visibility on search engines. In the context of the video, it is a key concept because NextJS is presented as a solution to the SEO limitations of traditional React applications, which are not friendly to search engine bots. The script explains how NextJS helps in creating websites that can be indexed by search engines like Google, thereby improving their search rankings.

💡Client-side Rendering

Client-side rendering refers to the process where HTML, CSS, and JavaScript are downloaded by the browser, and then JavaScript takes over to render the page. The video script uses this term to contrast traditional React applications with NextJS, pointing out that the former's reliance on client-side rendering can lead to SEO issues because search engine bots cannot effectively index JavaScript-rendered content.

💡First Contextual Paint

First Contextual Paint is a core web vital that measures the time it takes for the first piece of content to be painted on the screen. The video script discusses how client-side rendering in React applications can delay this metric, negatively impacting user experience and SEO. NextJS is presented as a solution to improve this metric by serving pre-rendered content.

💡Static Site Generation

Static Site Generation is one of the page building strategies in NextJS that converts a site into a static site before hand, which allows for faster delivery and better indexing by search engines and social media bots. The script explains that this method is suitable for sites with infrequent data changes and uses the example of a blog with one thousand posts being converted into a static site for improved performance.

💡getStaticProps()

getStaticProps() is a method in NextJS that is used in conjunction with Static Site Generation. It allows developers to fetch data that will be used to render pages at build time. The video script illustrates its use by stating that when a site is exported and built, NextJS uses this method to convert React components into a static site, which can then be cached via a CDN for fast content delivery.

💡Server Side Rendering

Server Side Rendering is another page building strategy discussed in the video script where the server generates the HTML content for a page on the fly. This method is beneficial for sites with rapidly changing data, as it allows for the delivery of fresh content with each request. The script contrasts this with Static Site Generation, noting that it provides updated content without the need to rebuild the entire site.

💡getServerSideProps()

getServerSideProps() is a method in NextJS used for Server Side Rendering, allowing data to be fetched from the server for each request. The video script explains that by implementing this method, a page can serve static HTML to the user while still fetching fresh content from the server, improving both user experience and SEO.

💡CDN

CDN, or Content Delivery Network, is a system of distributed servers that deliver web content to users based on their geographic location. The video script mentions CDNs in the context of caching and delivering static site content, highlighting their role in improving page load speeds and enhancing user experience.

💡revalidate

revalidate is a key in NextJS's getStaticProps() method that allows for content to be refreshed at regular intervals. The video script describes this as a middle ground between Static Site Generation and Server Side Rendering, where the site can be both static and periodically updated, ensuring that users see the most recent content.

💡Rust Compiler

The Rust Compiler mentioned in the video script is a new addition to NextJS that contributes to its performance improvements. While the script does not delve into technical details, it emphasizes the compiler's role in making NextJS faster, which is a significant aspect of the framework's appeal to developers and companies.

Highlights

NextJS is a React framework built and maintained by Vercel.

It is used for making SEO friendly websites.

Popular companies like Netflix, Github, Uber, and Starbucks use NextJS.

React applications are typically rendered on the client side.

Client-side rendering is not SEO friendly.

Social media bots cannot generate previews for client-side rendered content.

NextJS solves SEO issues by pre-rendering content.

NextJS uses file-based routing for URL structure.

Static Site Generation converts dynamic sites into static sites for faster delivery.

getStaticProps() is used for pre-rendering pages in Static Site Generation.

CDNs optimize content delivery for faster page speeds.

Server Side Rendering is used for sites with frequently changing data.

getServerSideProps() fetches data on the server for each request.

Revalidate key in getStaticProps() allows for periodic content updates.

NextJS is free, open source, and has a new version with a Rust compiler for increased speed.

NextJS enhances the capabilities of React by addressing SEO and performance issues.

Transcripts

play00:00

NextJS is a very amazing react framework

play00:02

Which is build and maintained by a company named Vercel

play00:06

It is mainly used for

play00:08

Making SEO friendly websites

play00:10

And it is used by companies like Netflix, Github, Uber and Starbucks

play00:14

When React is already so popular

play00:16

Then why do all these companies use NextJS

play00:19

Let's find out

play00:20

A typical React application is rendered on client site

play00:23

Which means HTML, CSS and JavaScript is downloaded by the browser

play00:28

After that, JavaScript takes over and renders the whole page

play00:32

Because of which browser gets one bundle

play00:34

After that, all the other things like

play00:36

Painting the content

play00:37

Downloading an asset

play00:39

And along with that, posting a blog or populating images

play00:42

All these tasks are done by JavaScript

play00:44

Although this approach sounds really good

play00:46

But this approach has some downsides

play00:48

One biggest downside is

play00:49

This is not a SEO friendly approach

play00:51

Because Bots like Google, cannot index these type of websites

play00:56

Along with that if we talk about social meadia bots like Facebook, Google, Twitter

play00:59

You guys must have seen sometimes

play01:01

When you share the link of any social media post on WhatApp or other application

play01:05

Then a preview image is generated

play01:06

And a preview text is also generated which means,

play01:08

Ahead of time, without visitng the page

play01:10

These social media bots read the content of your page

play01:14

Now all the content in React is populated through JavaScript

play01:17

So JavaScript cannot be executed

play01:19

Because of which social meadia bots cannot generate these type of previews

play01:24

So by using React application in this way, the search rankings drop greatly

play01:29

The reason for this is, it takes a lot of time for the First Contextual Paint to appear

play01:34

And according to core web vitals, this is not a good thing

play01:37

It does not give a good user experience

play01:39

NextJS solves this big problem

play01:41

By introducing page building strategies

play01:44

NextJS works on a simple principle

play01:46

That whatever data your browser will receive

play01:48

It will already have content

play01:50

Which means the main content will not be fetched by JavaScript

play01:54

For a blog, the main content is the preview image and the post content

play01:58

So this content will either come already generated from the server

play02:02

Or else it is already build and converted to cache through a CDN

play02:06

Not just this, NextJS has a lot of built-in features

play02:10

Like file-based routing

play02:11

In file-based routing you can simply make files in your source code

play02:16

And after making these files, your URL structures

play02:21

Will come according to these files

play02:22

For example, if I make a component named index.js in my pages folder

play02:27

And a component named blog.js

play02:29

And a component named contact.js

play02:32

So whenever I visit slash (/) blog slash contact

play02:35

Or visit the homepage of the website

play02:37

Then I can see all these React components by default

play02:41

I don't have to use any external router

play02:45

Typically this task in React is done by React router package named DOM

play02:48

Which is more or less development effort

play02:51

Along with this, for image optimization and to structure all the other contents

play02:56

There are many built-in utilities in NextJS

play02:59

Now lets talk about the most important feature of NextJS

play03:02

Which is page building strategies

play03:03

In Page Building Strategies, the first strategy is

play03:06

Static Site Generation

play03:08

In this, NextJS converts your whole site into a static site, before hand

play03:13

For example, you have written a blog which consists of one thousand posts

play03:17

Then your dynamic blog of one thousand posts will be coverted into a static website

play03:23

So that its delivery is fast

play03:25

And socila media bots and search engine bots are able to read your site properly

play03:29

For doing this, all pages can implement a method named getStaticProps()

play03:35

Which will return some props, which will be passed to that page again

play03:40

By doing this, whenever you will export the next time and try to build your whole website

play03:46

Then your whole NextJS website, which some way or the other uses React components only

play03:52

It will be coverted into a static site

play03:54

Which you can convert into cache through a CDN

play03:57

Which means your content delivery will be very fast

play04:00

Difference between a CDN and VPS is that

play04:02

CDN is optimized for content delivery

play04:05

Which means, your users will get very fast page speeds

play04:09

But this strategy is only good for those sites in which data is not changed so often

play04:14

If your data changes very quickly

play04:17

Then you can use another page building strategy whose name is Server Side Rendering

play04:24

In Server Side Rendering, every page can implement a method named getserverside props

play04:30

And after implementing this, the resulting props

play04:34

For example, in your getServerSideProp() you can request a fetch

play04:40

And you can get that data from fetchAPI

play04:42

Or you can pass the same component as props

play04:45

By doing this, whenever an user will visit your page

play04:49

They will get the static page after all their work is done on the server

play04:54

So the user will think your site is giving all the static HTML

play04:58

But in reality, your site is doing some work on the server

play05:02

To fetch your content from the database

play05:05

So the users and the social media bots and the search engine bots

play05:09

Will get the thing which they need

play05:11

Which makes them happy and which makes your ranking good

play05:15

Along with that, your user will also get satisfaction

play05:19

Because your core web vitals will be amazing

play05:22

Your first contextual paint time will be short

play05:25

And, because your content is changing very fast

play05:28

You can see all those changes implementing on the fly

play05:32

If we talk about Static Site generation

play05:34

Until you build your site again, you won't be able to see the updated content

play05:38

But by using this strategy, you will always see the updated content

play05:43

If you want your content to keep refreshing also

play05:46

And along with that you also want to build a static site

play05:50

Then you can use a page building strategy in between these two

play05:53

In which you can pass a key named revalidate in getstaticprops

play05:58

By doing this, whenever your server will receive a request

play06:01

Then your website will rebuild again after a certain period of time

play06:06

I hope I have explained it to guys what NextJS is

play06:10

And how does it makes the powers of React more better

play06:14

You guys must try NextJS, its new version is out now

play06:17

And its completely free and open source and an amazing framework

play06:21

There is a Rust compiler in its new version

play06:24

Which makes it more fast

play06:26

And in today's date people prefer using it even more

play06:30

I hope you must have learned something new from this video

play06:33

Thank you so much guys for watching this video

play06:34

And I will see you next time

Rate This

5.0 / 5 (0 votes)

Related Tags
NextJSReactSEOSSGSSRVercelStatic SitesDynamic DataWeb VitalsPerformance