Skip to content

Commit 4d4a181

Browse files
committed
NextJS - Update Pages SLUG
1 parent 478f391 commit 4d4a181

File tree

4 files changed

+143
-141
lines changed

4 files changed

+143
-141
lines changed
Lines changed: 0 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,2 @@
1-
---
2-
title : Best Practices for NextJS projects
3-
sidebar_label : Best Practices
4-
---
5-
6-
# Best Practices for NextJS
7-
8-
<SubHeading>This page documents simple practices you can use to ease development flow with Nextjs but to also help increase performances.</SubHeading>
9-
10-
Next.js has changed the way web applications are built with React and deployed. The developer experience guaranteed by the framework allows to develop with better architecture and allows custom optimization.
111

122
![Best Practices for NextJS - Tutorial provided by AppSeed.](https://github-production-user-asset-6210df.s3.amazonaws.com/51070104/270271822-7d508468-319c-4576-90d3-45e6a54a16d4.jpg)
13-
14-
Let's explore some best practices that can be used in a Next.js project from development to deployment.
15-
16-
## ✅ Dynamic Imports
17-
18-
Dynamic import also called code splitting is a practice of dividing bundles of JavaScript code into smaller chunks,
19-
which are then pieced together and charged into the runtime of an application and can boost your website performance.
20-
21-
But how dynamic imports are different from static imports? Dynamic imports work by applying the code splitting method.
22-
23-
It's the division of code into various bundles, which are arranged in parallel using a three format, where modules are loaded dynamically.
24-
25-
You can learn more about code splitting [here](https://nextjs.org/learn/foundations/how-nextjs-works/code-splitting).
26-
27-
Next.js provides an extension called `dynamic` from `next/dynamic`. It enables lazy loading of external libraries improving the loading performance of these libraries.
28-
29-
```jsx
30-
import dynamic from 'next/dynamic'
31-
import { Suspense } from 'react'
32-
33-
export default function Home() {
34-
const DynamicFooter = dynamic(
35-
() => import("./components/DynamicFooter"), {
36-
suspense: true,
37-
}));
38-
39-
return (
40-
<div>
41-
<Suspense fallback={<div>Loading...</div>}>
42-
<DynamicFooter />
43-
</Suspense>
44-
</div>
45-
)
46-
}
47-
```
48-
49-
By using `next/dynamic` in the example above, the footer component will not be included in the page's initial JavaScript bundle. The page will render the Suspense fallback first, followed by the Footer component when the Suspense boundary is resolved.
50-
51-
You can learn more from the dynamic imports on the official [documentation](https://nextjs.org/docs/advanced-features/dynamic-import).
52-
53-
## ✅ Optimization of Images
54-
55-
Image optimization with Next.js improves the user experience but is also essential in **Search Engine Optimization** (SEO) ranking when done right.
56-
57-
`Next.js` provides an image component `<Image />` that is very flexible and scalable.
58-
59-
We made use of this component in the recent [document](https://docs.appseed.us/technologies/next-js/deploy-a-next.js-application-on-netlify) while deploying the Next.js application.
60-
61-
But here is an example using a component using the `<Image />` component.
62-
63-
```jsx
64-
import Image from "next/image";
65-
66-
const loader = ({ src, width, quality }) => {
67-
return `https://website.com/${src}?w=${width}&q=${quality || 50}`;
68-
};
69-
70-
const BannerImage = (props) => {
71-
return <Image loader={loader} src="banner.png" alt="Banner of product" width={1200} height={500} />;
72-
};
73-
```
74-
75-
## ✅ Rendering mode
76-
77-
Next.js has three rendering modes:
78-
79-
### **Server Side Rendering** (SSR)
80-
81-
In this mode, pages are generated and returned after each page view. It is similar to how pages are returned in WordPress but in a much faster way.
82-
83-
SSR is used to fetch data and pre-populate a page with custom content, leveraging the server's reliable internet connection.
84-
85-
### **Static Site Generation** (SSG)
86-
87-
This is the way early websites used to work. HTML files are just stored on disc on a web server and each request on a URL returns a page that loads in the browser.
88-
89-
With SSG, your pages are generated during `Next.js` build step. These pages are then served on a server. This is really fast.
90-
91-
### **Incrementation Site Regeneration** (ISR)
92-
93-
ISR will create each page using SSR initially and store the response the same way SSG does.
94-
Subsequent requests for the same page will now be read from disc and be, you know, super-fast.
95-
96-
ISR enables you to use static generation on a per-page basis, without needing to rebuild the entire site. With ISR, you can retain the benefits of static while scaling to millions of pages.
97-
98-
## ✅ Lazy loading
99-
100-
You might want to load data only under certain circumstances. For example, you want to charge more data when the user scrolls to the bottom of the page or clicks a button.
101-
102-
It can also happen when you have external scripts you want to charge on the page. This can increase the loading time of the web page and causes a poor user experience.
103-
104-
Using Next.js, you have four loading strategies with [`next/script`](https://nextjs.org/docs/api-reference/next/script):
105-
106-
- `afterInteractive` which loads the script immediately after the page is made interactive. This is the default mode.
107-
- `beforeInteractive` loads the script before the page becomes interactive.
108-
- `lazyOnload` which loads when the page is idle.
109-
- `worker` loads the script in a web worker.
110-
111-
```jsx
112-
import { useState } from "react";
113-
import Script from "next/script";
114-
115-
export default function Home() {
116-
const [stripe, setStripe] = useState(null);
117-
118-
return (
119-
<>
120-
<Script
121-
id="stripe-js"
122-
strategy="beforeInteractive"
123-
src="https://js.stripe.com/v3/"
124-
onLoad={() => {
125-
setStripe({ stripe: window.Stripe("pk_test_12345") });
126-
}}
127-
/>
128-
</>
129-
);
130-
}
131-
```
132-
133-
## ✅ In Summary
134-
135-
Following the best practices above will help you make powerful Next.js websites.
136-
These practices are used to better the developer experience but also make it easier for the user to navigate your website, thus creating a rich user experience.
137-
138-
## ✅ Resources
139-
140-
- 👉 Access [AppSeed](https://appseed.us/) for more starters and support
141-
- 👉 [Deploy Projects on Aws, Azure and DO](https://www.docs.deploypro.dev/) via **DeployPRO**
142-
- 👉 Create landing pages with [Simpllo, an open-source site builder](https://www.simpllo.com/)
143-
- 👉 Build apps with [Django App Generator](https://app-generator.dev/django/) (free service)
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
2+
title : Best Practices for NextJS projects
3+
sidebar_label : Best Practices
4+
---
5+
6+
# Best Practices for NextJS
7+
8+
<SubHeading>This page documents simple practices you can use to ease development flow with Nextjs but to also help increase performances.</SubHeading>
9+
10+
Next.js has changed the way web applications are built with React and deployed. The developer experience guaranteed by the framework allows to develop with better architecture and allows custom optimization.
11+
12+
![Best Practices for NextJS - Tutorial provided by AppSeed.](https://github-production-user-asset-6210df.s3.amazonaws.com/51070104/270271822-7d508468-319c-4576-90d3-45e6a54a16d4.jpg)
13+
14+
Let's explore some best practices that can be used in a Next.js project from development to deployment.
15+
16+
## ✅ Dynamic Imports
17+
18+
Dynamic import also called code splitting is a practice of dividing bundles of JavaScript code into smaller chunks,
19+
which are then pieced together and charged into the runtime of an application and can boost your website performance.
20+
21+
But how dynamic imports are different from static imports? Dynamic imports work by applying the code splitting method.
22+
23+
It's the division of code into various bundles, which are arranged in parallel using a three format, where modules are loaded dynamically.
24+
25+
You can learn more about code splitting [here](https://nextjs.org/learn/foundations/how-nextjs-works/code-splitting).
26+
27+
Next.js provides an extension called `dynamic` from `next/dynamic`. It enables lazy loading of external libraries improving the loading performance of these libraries.
28+
29+
```jsx
30+
import dynamic from 'next/dynamic'
31+
import { Suspense } from 'react'
32+
33+
export default function Home() {
34+
const DynamicFooter = dynamic(
35+
() => import("./components/DynamicFooter"), {
36+
suspense: true,
37+
}));
38+
39+
return (
40+
<div>
41+
<Suspense fallback={<div>Loading...</div>}>
42+
<DynamicFooter />
43+
</Suspense>
44+
</div>
45+
)
46+
}
47+
```
48+
49+
By using `next/dynamic` in the example above, the footer component will not be included in the page's initial JavaScript bundle. The page will render the Suspense fallback first, followed by the Footer component when the Suspense boundary is resolved.
50+
51+
You can learn more from the dynamic imports on the official [documentation](https://nextjs.org/docs/advanced-features/dynamic-import).
52+
53+
## ✅ Optimization of Images
54+
55+
Image optimization with Next.js improves the user experience but is also essential in **Search Engine Optimization** (SEO) ranking when done right.
56+
57+
`Next.js` provides an image component `<Image />` that is very flexible and scalable.
58+
59+
We made use of this component in the recent [document](https://docs.appseed.us/technologies/next-js/deploy-a-next.js-application-on-netlify) while deploying the Next.js application.
60+
61+
But here is an example using a component using the `<Image />` component.
62+
63+
```jsx
64+
import Image from "next/image";
65+
66+
const loader = ({ src, width, quality }) => {
67+
return `https://website.com/${src}?w=${width}&q=${quality || 50}`;
68+
};
69+
70+
const BannerImage = (props) => {
71+
return <Image loader={loader} src="banner.png" alt="Banner of product" width={1200} height={500} />;
72+
};
73+
```
74+
75+
## ✅ Rendering mode
76+
77+
Next.js has three rendering modes:
78+
79+
### **Server Side Rendering** (SSR)
80+
81+
In this mode, pages are generated and returned after each page view. It is similar to how pages are returned in WordPress but in a much faster way.
82+
83+
SSR is used to fetch data and pre-populate a page with custom content, leveraging the server's reliable internet connection.
84+
85+
### **Static Site Generation** (SSG)
86+
87+
This is the way early websites used to work. HTML files are just stored on disc on a web server and each request on a URL returns a page that loads in the browser.
88+
89+
With SSG, your pages are generated during `Next.js` build step. These pages are then served on a server. This is really fast.
90+
91+
### **Incrementation Site Regeneration** (ISR)
92+
93+
ISR will create each page using SSR initially and store the response the same way SSG does.
94+
Subsequent requests for the same page will now be read from disc and be, you know, super-fast.
95+
96+
ISR enables you to use static generation on a per-page basis, without needing to rebuild the entire site. With ISR, you can retain the benefits of static while scaling to millions of pages.
97+
98+
## ✅ Lazy loading
99+
100+
You might want to load data only under certain circumstances. For example, you want to charge more data when the user scrolls to the bottom of the page or clicks a button.
101+
102+
It can also happen when you have external scripts you want to charge on the page. This can increase the loading time of the web page and causes a poor user experience.
103+
104+
Using Next.js, you have four loading strategies with [`next/script`](https://nextjs.org/docs/api-reference/next/script):
105+
106+
- `afterInteractive` which loads the script immediately after the page is made interactive. This is the default mode.
107+
- `beforeInteractive` loads the script before the page becomes interactive.
108+
- `lazyOnload` which loads when the page is idle.
109+
- `worker` loads the script in a web worker.
110+
111+
```jsx
112+
import { useState } from "react";
113+
import Script from "next/script";
114+
115+
export default function Home() {
116+
const [stripe, setStripe] = useState(null);
117+
118+
return (
119+
<>
120+
<Script
121+
id="stripe-js"
122+
strategy="beforeInteractive"
123+
src="https://js.stripe.com/v3/"
124+
onLoad={() => {
125+
setStripe({ stripe: window.Stripe("pk_test_12345") });
126+
}}
127+
/>
128+
</>
129+
);
130+
}
131+
```
132+
133+
## ✅ In Summary
134+
135+
Following the best practices above will help you make powerful Next.js websites.
136+
These practices are used to better the developer experience but also make it easier for the user to navigate your website, thus creating a rich user experience.
137+
138+
## ✅ Resources
139+
140+
- 👉 Access [AppSeed](https://appseed.us/) for more starters and support
141+
- 👉 [Deploy Projects on Aws, Azure and DO](https://www.docs.deploypro.dev/) via **DeployPRO**
142+
- 👉 Create landing pages with [Simpllo, an open-source site builder](https://www.simpllo.com/)
143+
- 👉 Build apps with [Django App Generator](https://app-generator.dev/django/) (free service)
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)