Unverified Commit 779a3734 authored by Lee Robinson's avatar Lee Robinson Committed by GitHub
parent bb7af2a0
...@@ -446,3 +446,4 @@ module.exports = withMDX({ ...@@ -446,3 +446,4 @@ module.exports = withMDX({
- [`@next/mdx`](https://www.npmjs.com/package/@next/mdx) - [`@next/mdx`](https://www.npmjs.com/package/@next/mdx)
- [remark](https://github.com/remarkjs/remark) - [remark](https://github.com/remarkjs/remark)
- [rehype](https://github.com/rehypejs/rehype) - [rehype](https://github.com/rehypejs/rehype)
- [Markdoc](https://markdoc.dev/docs/nextjs)
...@@ -9,42 +9,36 @@ This guide will help you migrate an existing Vite application to Next.js. ...@@ -9,42 +9,36 @@ This guide will help you migrate an existing Vite application to Next.js.
There are several reasons why you might want to switch from Vite to Next.js: There are several reasons why you might want to switch from Vite to Next.js:
1. **Slow initial page loading time**: If you have built your application with the [default Vite ### Slow initial page loading time
plugin for React](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react),
your application is a purely client-side application. Client-side only applications, also known as If you have built your application with the [default Vite plugin for React](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react), your application is a purely client-side application. Client-side only applications, also known as single-page applications (SPAs), often experience slow initial page loading time. This happens due to a couple of reasons:
single-page applications (SPAs), often experience slow initial page loading time. This
happens due to a couple of reasons: 1. The browser needs to wait for the React code and your entire application bundle to download and run before your code is able to send requests to load some data.
1. The browser needs to wait for the React code and your entire application bundle to download 2. Your application code grows with every new feature and extra dependency you add.
and run before your code is able to send requests to load some data.
2. Your application code grows with every new feature and extra dependency you add. ### No automatic code splitting
2. **No automatic code splitting**: The previous issue of slow loading times can be somewhat managed with code splitting.
However, if you try to do code splitting manually, you'll often make performance worse. It's easy The previous issue of slow loading times can be somewhat managed with code splitting. However, if you try to do code splitting manually, you'll often make performance worse. It's easy to inadvertently introduce network waterfalls when code-splitting manually. Next.js provides automatic code splitting built into its router.
to inadvertently introduce network waterfalls when code-splitting manually. Next.js provides
automatic code splitting built into its router. ### Network waterfalls
3. **Network waterfalls**: A common cause of poor performance occurs when applications make
sequential client-server requests to fetch data. One common pattern for data fetching in an SPA A common cause of poor performance occurs when applications make sequential client-server requests to fetch data. One common pattern for data fetching in an SPA is to initially render a placeholder, and then fetch data after the component has mounted. Unfortunately, this means that a child component that fetches data can't start fetching until the parent component has finished loading its own data. With Next.js, [this issue is resolved](https://github.com/reactjs/rfcs/blob/main/text/0188-server-components.md#no-client-server-waterfalls) by fetching data in Server Components.
is to initially render a placeholder, and then fetch data after the component has mounted.
Unfortunately, this means that a child component that fetches data can't start fetching until ### Fast and intentional loading states
the parent component has finished loading its own data. On Next.js,
[this issue is resolved](https://github.com/reactjs/rfcs/blob/main/text/0188-server-components.md#no-client-server-waterfalls) Thanks to built-in support for [Streaming with Suspense](/docs/app/building-your-application/routing/loading-ui-and-streaming#streaming-with-suspense), with Next.js, you can be more intentional about which parts of your UI you want to load first and in what order without introducing network waterfalls. This enables you to build pages that are faster to load and also eliminate [layout shifts](https://web.dev/cls/).
by fetching data in Server Components.
4. **Fast and intentional loading states**: Thanks to built-in support for ### Choose the data fetching strategy
[Streaming with Suspense](/docs/app/building-your-application/routing/loading-ui-and-streaming#streaming-with-suspense),
with Next.js, you can be more intentional about which parts of your UI you want to load first and Depending on your needs, Next.js allows you to choose your data fetching strategy on a page and component basis. You can decide to fetch at build time, at request time on the server, or on the client. For example, you can fetch data from your CMS and render your blog posts at build time, which can then be efficiently cached on a CDN.
in what order without introducing network waterfalls. This enables you to build pages that are
faster to load and also eliminate [layout shifts](https://web.dev/cls/). ### Middleware
5. **Choose the data fetching strategy**: Depending on your needs, Next.js allows you to choose your
data fetching strategy on a page and component basis. You can decide to fetch at build time, at [Next.js Middleware](/docs/app/building-your-application/routing/middleware) allows you to run code on the server before a request is completed. This is especially useful to avoid having a flash of unauthenticated content when the user visits an authenticated-only page by redirecting the user to a login page. The middleware is also useful for experimentation and [internationalization](/docs/app/building-your-application/routing/internationalization).
request time on the server, or on the client. For example, you can fetch data from your CMS and
render your blog posts at build time, which can then be efficiently cached on a CDN. ### Built-in Optimizations
6. **Middleware**: [Next.js Middleware](/docs/app/building-your-application/routing/middleware)
allows you to run code on the server before a request is completed. This is especially useful to [Images](/docs/app/building-your-application/optimizing/images), [fonts](/docs/app/building-your-application/optimizing/fonts), and [third-party scripts](/docs/app/building-your-application/optimizing/scripts) often have significant impact on an application's performance. Next.js comes with built-in components that automatically optimize those for you.
avoid having a flash of unauthenticated content when the user visits an authenticated-only page
by redirecting the user to a login page. The middleware is also useful for experimentation and
internationalization.
7. **Built-in Optimizations**: Images, fonts, and third-party scripts often have significant impact
on an application's performance. Next.js comes with built-in components that automatically
optimize those for you.
## Migration Steps ## Migration Steps
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment