Fireship · @fireship

Next.js 12 is a Beast

Uploaded October 27, 2021 · Length 5:08

Next.js 12 is a Beast

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.

  1. 0:00

    just yesterday next js announced version

  2. 0:02

    12 and it was even more impressive than

  3. 0:04

    apple's new macbook announcements which

  4. 0:05

    is pretty mind-blowing considering it's

  5. 0:07

    just a free javascript framework they're

  6. 0:09

    setting the bar really high for what a

  7. 0:10

    full stack javascript framework is

  8. 0:12

    expected to do like it now ships with a

  9. 0:14

    rust compiler instead of javascript to

  10. 0:16

    give you 5x faster builds you don't need

  11. 0:18

    to know rest it just makes next faster

  12. 0:20

    under the hood by replacing babel which

  13. 0:22

    is important because big complex apps

  14. 0:24

    tend to have slow build times and i've

  15. 0:26

    already updated my full next.js course

  16. 0:28

    to use version 12. and i'm seeing

  17. 0:29

    significantly faster refresh and build

  18. 0:31

    times that's pretty amazing but it's not

  19. 0:33

    even close to being the coolest feature

  20. 0:34

    in this release let's take a look at all

  21. 0:36

    the new features in x12 and more

  22. 0:38

    importantly why you would want to use

  23. 0:39

    them if you're new here like and

  24. 0:40

    subscribe and if you want to get really

  25. 0:42

    good at next consider enrolling in my

  26. 0:43

    full course grab a discount in the

  27. 0:45

    description the first feature i want to

  28. 0:46

    look at is middleware middleware is not

  29. 0:48

    a new concept frameworks like express.js

  30. 0:51

    use middleware to intercept an http

  31. 0:53

    request and process it in some way

  32. 0:55

    before it goes to your actual route

  33. 0:57

    handler with something like next.js

  34. 0:58

    though things are a little more

  35. 1:00

    complicated on one hand you want your

  36. 1:01

    website to be really fast and the best

  37. 1:03

    way to make that happen is to cache

  38. 1:05

    pre-built html pages on a cdn but when

  39. 1:07

    you do that you lose the ability to make

  40. 1:09

    your pages dynamic so on the other end

  41. 1:11

    of the spectrum you have server side

  42. 1:13

    rendering that uses a node server to

  43. 1:15

    fetch data from a database or api when

  44. 1:17

    the incoming request comes in but that

  45. 1:19

    is slow and inefficient in a perfect

  46. 1:21

    world though developers would have both

  47. 1:23

    speed and dynamic content at the same

  48. 1:25

    time and next is really leading the way

  49. 1:27

    to make that happen resell the company

  50. 1:29

    behind next has a product called edge

  51. 1:31

    functions these are serverless functions

  52. 1:33

    like aws lambda or google cloud

  53. 1:35

    functions except they're deployed to the

  54. 1:37

    edge like a cdn so your end users get

  55. 1:39

    extremely fast execution with no cold

  56. 1:41

    starts now here's where middleware comes

  57. 1:43

    in in your project create a file called

  58. 1:45

    underscore middleware in the pages

  59. 1:47

    directory from inside it you can export

  60. 1:49

    a function called middleware this

  61. 1:51

    function will give you access to the

  62. 1:52

    incoming request and allow you to modify

  63. 1:54

    it and it will run before rendering

  64. 1:56

    takes place for every page in the pages

  65. 1:58

    directory you can also scope the