Fireship · @fireship
Next.js 12 is a Beast
Uploaded October 27, 2021 · Length 5:08
Summary
Fireship reviews Next.js 12 features, including middleware, concurrent mode, server components, and module imports.
- next js 12
- next js middleware
- react concurrent mode
- server components next js
- next js module imports
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
just yesterday next js announced version
- 0:02
12 and it was even more impressive than
- 0:04
apple's new macbook announcements which
- 0:05
is pretty mind-blowing considering it's
- 0:07
just a free javascript framework they're
- 0:09
setting the bar really high for what a
- 0:10
full stack javascript framework is
- 0:12
expected to do like it now ships with a
- 0:14
rust compiler instead of javascript to
- 0:16
give you 5x faster builds you don't need
- 0:18
to know rest it just makes next faster
- 0:20
under the hood by replacing babel which
- 0:22
is important because big complex apps
- 0:24
tend to have slow build times and i've
- 0:26
already updated my full next.js course
- 0:28
to use version 12. and i'm seeing
- 0:29
significantly faster refresh and build
- 0:31
times that's pretty amazing but it's not
- 0:33
even close to being the coolest feature
- 0:34
in this release let's take a look at all
- 0:36
the new features in x12 and more
- 0:38
importantly why you would want to use
- 0:39
them if you're new here like and
- 0:40
subscribe and if you want to get really
- 0:42
good at next consider enrolling in my
- 0:43
full course grab a discount in the
- 0:45
description the first feature i want to
- 0:46
look at is middleware middleware is not
- 0:48
a new concept frameworks like express.js
- 0:51
use middleware to intercept an http
- 0:53
request and process it in some way
- 0:55
before it goes to your actual route
- 0:57
handler with something like next.js
- 0:58
though things are a little more
- 1:00
complicated on one hand you want your
- 1:01
website to be really fast and the best
- 1:03
way to make that happen is to cache
- 1:05
pre-built html pages on a cdn but when
- 1:07
you do that you lose the ability to make
- 1:09
your pages dynamic so on the other end
- 1:11
of the spectrum you have server side
- 1:13
rendering that uses a node server to
- 1:15
fetch data from a database or api when
- 1:17
the incoming request comes in but that
- 1:19
is slow and inefficient in a perfect
- 1:21
world though developers would have both
- 1:23
speed and dynamic content at the same
- 1:25
time and next is really leading the way
- 1:27
to make that happen resell the company
- 1:29
behind next has a product called edge
- 1:31
functions these are serverless functions
- 1:33
like aws lambda or google cloud
- 1:35
functions except they're deployed to the
- 1:37
edge like a cdn so your end users get
- 1:39
extremely fast execution with no cold
- 1:41
starts now here's where middleware comes
- 1:43
in in your project create a file called
- 1:45
underscore middleware in the pages
- 1:47
directory from inside it you can export
- 1:49
a function called middleware this
- 1:51
function will give you access to the
- 1:52
incoming request and allow you to modify
- 1:54
it and it will run before rendering
- 1:56
takes place for every page in the pages
- 1:58
directory you can also scope the


