跟讀練習: Next.js in 100 Seconds // Plus Full Beginner's Tutorial - 通過影片學習英語口語
選擇練習模式
每種模式都會開啟全屏練習室。
163 句
如果句子過短或過長,請點選 Edit 進行調整。
1
Next .js, create fast, search engine optimized
2
React apps with zero configuration.
3
A traditional React app is rendered client -side, where the browser starts with a shell of an HTML page lacking any rendered content.
4
From there, the browser fetches the JavaScript file containing the React code to render content to the page and make it interactive.
5
But there are two major drawbacks with client -side rendering.
6
One, the content is not reliably indexed by all search engines or read by social media linkbots.
7
And two, it can take longer to reach the first contentful paint when a user first lands on the web page.
8
Next is a framework that allows you to build a React app, but render the content in advance on the server,
9
so the first thing a user or a search bot sees is the fully rendered HTML.
10
After receiving this initial page, client -side rendering takes over, and it works just like a traditional React app.
11
It's the best of both worlds.
12
Fully rendered content for bots, highly interactive content for users.
13
Inside of a Next project, you have a Pages directory.
14
Each JavaScript file defined here exports a React component that represents a route in the application.
15
In other words, the file structure here mirrors the actual URLs that the user will navigate to,
16
and Next provides its own router to make navigation seamless.
17
But the real magic comes into play when we talk about data fetching, because Next can perform multiple server rendering strategies from a single project.
18
Static generation, or pre -rendering, allows you to render your pages at build time.
19
Each page or component can implement a function called getStaticProps.
20
It might fetch data from a cloud database, then pass the data as props to the component.
21
You can then build your app to render out all the HTML locally
22
and upload it to a storage bucket where it can be easily cached by a CDN.
23
That works great for a blog or any kind of app where the data doesn't change often.
24
But if the data does change often, you can implement server -side rendering, which builds the HTML page each time it's requested by the user.
25
In the component, we implement data fetching with the getServerSideProps function.
26
Instead of running at build time, this function runs at request time.
27
That means the page will fetch the latest data on the server each time a new request comes in.
28
That's great for pages with rapidly changing data, but maybe you want something in between.
29
Yet another option is incremental static regeneration.
30
By simply adding a revalidate option to get static props, Next can regenerate a page whenever a new request comes in within a certain time interval.
31
This has been Next .js in 100 seconds.
32
If you want to see more short videos like this, make sure to subscribe and hit the like button.
33
Then open up VS Code and get ready to go beyond 100 seconds with a full breakdown of Next.
34
Before we get going, I'd like to point out that I'm working on a full
35
React Next Firebase course, which I hope to have finally finished by the end of January, which will be available to Fireship Pro members.
36
My goal over the next few minutes is to teach you the fundamentals of Next
37
while also explaining the complexities of server side rendering.
38
To follow along, open up the terminal and run npx create next app followed by the name of your app.
39
And if you get lost at any point, make sure to grab the source code on GitHub or Fireship IO.
40
Let's open up the project in VS Code and then go into the package .json file.
41
In development, the only script we need to worry about is dev, which you can execute by running npm run dev from the command line,
42
which will run our app on localhost 3000.
43
That should give you the default boilerplate in the browser.
44
Now before we get into the React code, there's a few things that I want to point out.
45
First, in the styles directory here, you'll notice how
46
Next supports CSS modules.
47
In the globals file, you can define styles that apply to the entire application.
48
But in other files with .module, you can define classes that only apply to a specific route or component.
49
And you don't have to worry about coming up with a bunch of unique class names
50
or naming conventions when managing your styles.
51
If you want to use styles from a certain module, you just import the style sheet in your JavaScript,
52
then reference your styles in JSX as if the styles were a JavaScript object.
53
That's pretty awesome, but from there, let's shift our attention over to the pages directory.
54
Inside this directory, we define all of the pages and routes for the application.
55
At the highest level, we have this underscore app .js file, which is like the main entry point into the app.
56
In other words, every individual page will start from this template.
57
Currently, the application only has one page, which points to the root URL and is defined by the component in the index .js file.
58
When a user navigates to this URL, next will find the default export, which is a React component, in this file.
59
So every file or page in your application needs to have one default export.
60
To demonstrate this further, let's create our first route.
61
In the pages directory, create a new file called hello .js.
62
Then we can define the content of this page by exporting
63
a default react component from it from there we can go back to the browser
64
and navigate to localhost 3000 slash hello and we should get the content of
65
that component congratulations you just built your first web page with next
66
but now let's imagine a route that's a little more complex we have a cars route
67
that should show a list of cars then an infinite number of cars
68
that might be dynamically generated under that url we can implement a dynamic route like that by first creating a cars directory.
69
Then inside the directory, we'll add an index .js file.
70
which will show the main list of cars.
71
Then for each individual car, we'll add a component that has a file name of brackets param name dot j s.
72
The brackets make this route dynamic, which means anytime a user navigates to cars slash whatever, or cars slash
73
Tesla, it will render the component in this file.
74
To see that in action, let's go ahead and implement the component logic.
75
In the index file, we'll just add a placeholder for the cars list for now.
76
But in the dynamic component, we'll import the useRouter hook from the next router.
77
It allows us to access the query parameters from the URL.
78
In this example, the value is ID, but you can give it a name of whatever you want.
79
And then we'll render that value out to the template.
80
Now back in the browser, if we go to the cars URL, it renders out the cars component.
81
Then if we add any string after the cars URL, it renders out the dynamic component.
82
Now one other thing you may have noticed in the pages directory is this API directory.
83
So what is that all about?
84
The API directory is a special part of Next for setting up routes that will only apply to the server.
85
That can be useful because the code you write here won't increase the client -side JavaScript bundle
86
that needs to ultimately be sent over the network.
87
We're not going to get into API routes in this video,
88
but just know that it's a useful feature when you have work that needs to be done on the backend,
89
or if you simply want to expose an API for your end users.
90
But now, let's shift our attention over to the most valuable feature in Next, which of course is data fetching.
91
Next allows us to fetch data and render HTML on the server.
92
And again, the benefit of doing that is
93
that the end user gets rendered content quicker
94
and the content can be reliably crawled by search bots and social media link bots.
95
Now, when it comes to server rendering, there are two main options, static generation and server -side rendering.
96
Static generation is also called pre -rendering because you generate all the HTML at build time.
97
It makes life very simple because you generate a bunch of HTML files, then upload them to a storage bucket or static host,
98
and they can be delivered with very high performance over a CDN.
99
But there's a couple of big trade -offs here.
100
The first one is that your data may become stale.
101
If the data on the server changes, you need to rebuild and redeploy your site in order for those changes to be reflected.
102
Another important trade -off to think about is scale.
103
If your website has a million pages, it'll be very slow and difficult to pre -render all of them.
104
That makes static generation most well -suited for data
105
that doesn't change often and for sites that have a relatively low number of total pages.
106
A good example would be a blog, because it might have a few hundred pages and those pages likely don't change on a daily basis.
107
Let's go ahead and take a look at how we might implement static generation in Next.
108
In the car component, let's imagine we need to fetch data from an external source, like a database or API.
109
To simulate that for the demo, I've added a couple of JSON files to the public directory.
110
We have a file that returns an array of IDs, then an individual response for each car,
111
which contains an image and other data about the car.
112
Now we can fetch this data for the car component by implementing the get static props function inside the component file.
113
When you build your site, Next will automatically call this function, then send the result as props to the component itself.
114
What we want to do here is fetch the JSON for an individual car
115
so it can be used in the HTML or UI for the car page.
116
In this case, we need the ID from the URL to know which car was requested.
117
We can get that information from the params argument in the function.
118
Then from there, we'll use the fetch API to make a request to localhost to request the JSON file with that ID.
119
We can then convert it to JSON.
120
Then the final step is to return an object that has a props property, where each prop can then be accessed by the component.
121
Up in the component code, we can destructure the car prop and then use it in the JSX,
122
which I'm doing here by adding an image tag, which relies on the data fetched by the server as the image source.
123
Now if you're concerned about search engine optimization,
124
you likely want to add an SEO -friendly title as well as meta tags to the head of the document.
125
Next makes that very easy to accomplish by simply importing the head component.
126
Anything inside this component will be rendered out to the head of the document.
127
Like in this case, we add a title with the car color and ID.
128
And we could also add meta tags for Twitter and Facebook cards if we wanted to.
129
Now because we're working with a dynamic route, there's one other thing we have to keep in mind.
130
And that's the fact that
131
Next has no way of knowing how many pages we actually have associated to a dynamic route.
132
In order to pre -render all the car IDs, Next needs to know those IDs in advance.
133
And the way we provide that information is by implementing the get static paths function.
134
This function can also request data from an API or database,
135
then its job is to return a paths object that contains an array with every route for this dynamic URL.
136
In this demo, we only have three routes, Tesla, Ford, and Lambo.
137
We map those values to an array of objects, then return them from the function, along with additional options like the fallback behavior.
138
Now if we go visit the app in the browser.
139
we should see a fully rendered web page.
140
It doesn't look any different than a regular React app.
141
However, if you open up the Sources panel in Chrome DevTools, it'll show you the fully rendered HTML before it was touched by JavaScript.
142
Notice how it contains the title and pre -rendered content, which is essential for SEO and sharing content on social media sites.
143
So that's how you implement server -side generation.
144
But another big strategy is server -side rendering.
145
The big difference is that with SSR, the content is generated on a server when requested by the user.
146
This approach is ideal when data changes constantly
147
because it ensures the end user will always get the latest and greatest data from whatever your data source happens to be.
148
However, it's far less efficient because you need to have a server in place to respond to those requests,
149
as opposed to caching everything on a global CDN.
150
Imagine something like an eBay auction where you have millions of listings and those listings are changing all the time.
151
That's probably a good candidate for SSR.
152
In any case, it's very easy to implement a Next.
153
Back in our page file, we'll go ahead and implement another function called getServerSideProps.
154
The only thing that actually changes in our code is the name of the function.
155
We can simply copy the body of the getStaticProps function and paste it into our new function.
156
It does the exact same thing, but does it on every request instead of at build time.
157
Then we can comment out getStaticProps and getStaticPaths because we no longer need those functions.
158
But the real beauty of Next is that we can apply both of these paradigms wherever we want in the application.
159
We're not limited to one or the other.
160
I'm going to go ahead and wrap things up there.
161
If there's anything you want to see in my full
162
Next course, make sure to let me know in the comments.
163
Thanks for watching, and I will see you in the next one.
同頻道
FOR YOU
推薦影片
本課的詞彙與口語要點
這節口語課以影片“Next.js in 100 Seconds // Plus Full Beginner's Tutorial”為素材。 影片中反覆出現的詞有:page, component, file, server, route。 這段影片共有 163 個句子、2418 個單詞可供跟讀。 講話部分時長為 11:49。 說話人語速較快,每分鐘約 205 個詞,會出現較多連讀和弱讀。 只有 80% 的單詞屬於英語最常用的 3,000 詞,詞彙難度較高。
影片中的重點詞彙
影片中 15 個值得學習的單詞,附發音和釋義:
| 單詞 | 發音 | 釋義 |
|---|---|---|
| component 名詞 | /kəmˈpoʊ.nənt/ | 元件, 部件 |
| server 名詞 | /ˈsɝvɚ/ | 伺服器 /伺服器, 伺服器 |
| fetch 動詞 | /fɛt͡ʃ/ | 取 |
| implement 動詞 | /ˈɪmpləmənt/ | 實施 /實施, 執行 /執行 |
| directory 名詞 | /dɪˈɹɛktəɹi/ | 名錄 /名錄, 簿 |
| define 動詞 | /dɪˈfaɪn/ | 界定 |
| default 名詞 | /dɪˈfɔlt/ | 違約 /違約, 暴雷 |
| export 名詞 | /ˈɛks.pɔɹt/ | 出口, 輸出 /輸出 |
| database 名詞 | /ˈdeɪtəˌbeɪs/ | 資料庫 /資料庫 |
| import 名詞 | /ˈɪm.pɔɹt/ | 進口貨 /進口貨, 舶來品 /舶來品 |
| module 名詞 | /ˈmɑd͡ʒul/ | 模組 /模組 |
| bot 名詞 | /bɑt/ | 機器人 /機器人 |
| tag 名詞 | /tæɡ/ | 標簽 /標籤 |
| bucket 名詞 | /ˈbʌkɪt/ | 水桶, 吊桶 |
| demo 名詞 | /ˈdɛm.oʊ/ | 示範 /示範 |
影片中出現的短語動詞
| 單詞 | 發音 | 釋義 |
|---|---|---|
| go ahead 動詞 | /ˌɡoʊ əˈhɛd/ | 請便 /請便 |
| point out 動詞 | 指, 指出 | |
| come up with 動詞 | 想出, 提出 | |
| take over 動詞 | 接管, 接手 |
影片中的語法
說話人最常用的結構,並附上影片中的原話:
| 結構 | 影片中的用法 |
|---|---|
| 被動語態 be + 過去分詞 — 強調發生了什麼,而不是誰做的 | is rendered · is not reliably indexed · can be easily cached |
| 定語從句 who / which + 從句 — 補充說明人或事物 | January, which will · file, which is · export, which is |
| 現在完成時 have/has + 過去分詞 — 過去發生但與現在仍有關聯的事 | has been · I've added · have associated |
需要注意的發音
說話人用了 25 次縮略和弱讀形式,例如 we'll, doesn't, I'm。請按聽到的簡短形式來說。
- “sh” 和 “zh” 音: cache /kæʃ/, efficient /ɪˈfɪʃənt/, congratulations /kənˌɡɹæt͡ʃəˈleɪʃ(ə)nz/, sheet /ʃit/, shell /ʃɛl/
- 長單詞——注意重音位置: directory /dɪˈɹɛktəɹi/, interactive /ˌɪn.tɚˈæk.tɪv/, congratulations /kənˌɡɹæt͡ʃəˈleɪʃ(ə)nz/, fundamental /ˌfʌn.dəˈmɛn.təl/, navigation /nævɪˈɡeɪʃən/
中文母語者容易讀錯的音:
- /v/ — 不要讀成 /w/,上齒輕觸下唇: server /ˈsɝvɚ/, navigate /ˈnæv.ɪ.ɡeɪt/, interactive /ˌɪn.tɚˈæk.tɪv/, wherever /(h)wɛɹˈɛvɚ/, convert /kənˈvɝt/
- 詞尾子音 — 要讀清楚,後面不要加母音: component /kəmˈpoʊ.nənt/, fetch /fɛt͡ʃ/, implement /ˈɪmpləmənt/, react /ɹiːˈækt/, static /ˈstæt.ɪk/
- /r/ 和 /l/ 的區別: congratulations /kənˌɡɹæt͡ʃəˈleɪʃ(ə)nz/, reflect /ɹɪˈflɛkt/, rapidly /ˈɹæpɪdli/, rely /ɹɪˈlaɪ/, rebuild /ɹiːˈbɪld/
如何用這段影片練習
- 先完整聽一遍影片,不要開口,記下不認識的單詞。
- 先用 0.75 倍速逐句跟讀,熟練之後再回到正常速度。
- 錄下自己的聲音並與原聲對比,特別注意 component, server, fetch 這類單詞。
什麼是跟讀法?
跟讀法 (Shadowing) 是一種有科學依據的語言學習技巧,最初開發用於專業口譯員的培訓,並由多語言者Alexander Arguelles博士普及。這個方法簡單而強大:您在聽英語母語原聲的同時立即大聲重複——就像是一個延遲1-2秒緊跟說話者的影子。與被動聽力或語法練習不同,跟讀法強迫您的大腦和口腔肌肉同時處理並模模擬實的講話模式。研究表明它能顯著提高發音準確性,語調,節奏,連讀,聽力理解和口語流利度——使其成為雅思口語備考和真實英語交流最有效的方法之一。
































