Тёмный
No video :(

Next.js Static Site Generation (SSG) Tutorial 

Ben Awad
Подписаться 498 тыс.
Просмотров 81 тыс.
50% 1

Learn how to use static site generation in Next.js in this tutorial where I show you how you can setup.
Code: github.com/ben...
Markdown posts:
raw.githubuser...
raw.githubuser... ​

----
Follow me online: voidpet.com/be...
#benawad

Опубликовано:

 

5 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 143   
@bawad
@bawad 4 года назад
I was using incorrectly in the index.js page when navigating to dynamic pages you need to use href and as prop: nextjs.org/docs/api-reference/next/link#dynamic-routes should be: I updated the code on GitHub
@jeromesnail
@jeromesnail 4 года назад
Great video! One thing I would add is that when you build your static site, not alone the static HTML is rendered for pages using getStaticProps, but also next.js create a "virtual" API that serves JSON so that when your app is running, once you've loaded your first static page, the app will act like a normal client side react app. Hence the importance of the "as" prop in Link. If not use correctly it doesn't act like a SPA link but rather like a normal anchor tag. It's even worse when you use SSR as each page will be rendered on the server with browser refresh instead of just behaving like a SPA.
@JakelineSofiaCamposCabello
@JakelineSofiaCamposCabello 4 года назад
cherto!! Great video!
@JeremyBlackYoda
@JeremyBlackYoda 4 года назад
Hi Ben, thanks for catching that! I don't see the change on github index page - or is it somewhere else?
@illialukianov2803
@illialukianov2803 4 года назад
@@jeromesnail yep, but this is avaialable only with NextJS server right? Like they way Ben showed here - it is static site, as done in PHP or Python. The thing u r talking require NextJS to handle thos requests and can't be deployed to CDN easily without Vercel right? At least I am trying to find way to do this now, and didn't succeed yet. Do u have any ideas how to serve content of .next build folder from cdn without actual Next or Node server? Or at least with Nginx, not cdn?
@illialukianov2803
@illialukianov2803 4 года назад
@@jeromesnail because as far as I tested locally - Next gives u very low RPS like 10 (at least for our project, not very hard IMO) which is not enough for prod. From what I read - Vercel deploy each page as Lambda function, so it can scale it easily but what if I don't wanna use Vercel(Ziet)?
@violet-trash
@violet-trash 4 года назад
This is so much easier then Gatsby. No plugins, no configs, no bloat. It just works. ✋😌👌
@luismunoz9126
@luismunoz9126 4 года назад
No plugins, no Image optimization, no offline support, etc.
@r0mankon
@r0mankon 3 года назад
@@luismunoz9126 Yeah. but I believe those are not impossible to do. like offline support with "next-pwa/cache" or "next-offline". There should be for image optimization too. check out official examples... github.com/vercel/next.js/tree/canary/examples
@luismunoz9126
@luismunoz9126 3 года назад
@@r0mankon nice one, thanks i will take a look, it seems some things has changed for good in next js.
@luismunoz9126
@luismunoz9126 3 года назад
@@HarryManchanda i love the future
@chubbyshady
@chubbyshady 4 года назад
Add 'utf8' as a 2nd argument to readFileSync and will return a string
@shilangyu
@shilangyu 4 года назад
You can do `console.log({ files })` and `console.log({ paths })` to retain the variable name :)
@jeromesnail
@jeromesnail 4 года назад
I was about to say the same thing. I even use console.table({ myVariable }) to have a nicer output :p
@andredealbuquerque7699
@andredealbuquerque7699 4 года назад
Great video! The SGG and SSR part of next is something to figure out. Please upload more on Next.js ! Keep up the great work
@callumn-d846
@callumn-d846 4 года назад
Great overview, would love to hear more about how we can use SSR and Static in a hybrid app
@jjuuiiccyyjj
@jjuuiiccyyjj 4 года назад
^ this! great video btw :)
@temirzhanyussupov6997
@temirzhanyussupov6997 4 года назад
how would you explain what is a hybrid app?
@naynyamish270
@naynyamish270 4 года назад
@@temirzhanyussupov6997 a mix between static sites and webapp.
@jeromesnail
@jeromesnail 4 года назад
Basically you have nothing to do. Just use getStaticProps on your static pages, getInitialProps or getServerSideProps on your SSR pages, Next.js will do everything for you when you build you app, giving a summary of what pages are static, what pages are server side rendered. You can even export just the static site with next export, and put the output on a CDN, the app will work with static pages rendered at build and the rest of the app acting like a normal react app (without SSR). It's pretty amazing how easy Next.js is.
@yokiijay933
@yokiijay933 4 года назад
Thanks, it helped me a lot to understand the whole process. One detail should noticed, replace(/\.md$/, '') instead of replace('.md', '')
@RobertTodar
@RobertTodar 4 года назад
This is exactly what I was trying to figure out on my own. Thank you!!!! A nice bonus video would to be setting it up with netlifycms! 🤞
@divinenature6220
@divinenature6220 4 года назад
Yeah. I had to do mine another way. GitHub.com/DNature/divinehycenth.com
@maxiequa567
@maxiequa567 4 года назад
+1 For more Next.js and Headless CMS etc.
@ClaudioBernasconi
@ClaudioBernasconi 3 года назад
Thanks for this great introduction to static site generation using Next.js. I'm an experienced React app developer and I think that Next.js might be a great tool to build simple websites in the future for me.
@danieldosen5260
@danieldosen5260 2 года назад
never had a need for next, but now I do - this vid is helpful... next up - to see what changed in two years :)
@CoryTheSimmons
@CoryTheSimmons 4 года назад
So glad Next added dynamic routes. It's actually so good now.
@amandeepsbajwa
@amandeepsbajwa 4 года назад
Thanks Ben. That helps a lot. Please create more videos on NextJS
@kuscamara
@kuscamara 4 года назад
More Next tutorials please! 🙏 Thank you for this work.
@JeremyBlackYoda
@JeremyBlackYoda 4 года назад
Thanks Ben for an excellent and succinct overview of the newest features of nextjs static site creation. Love to see more on Nextjs - working with some css to make it look great. (Try Tailwind or Chakra!) and remote data fetching using an open source CMS or Database like Hasura or Strapi or NetlifyCMS (community version) . You are a spot on teacher... .
@SLP1177
@SLP1177 4 года назад
Great video Ben! I'd apreciate a video on upload files using next.js. Great job.
@jeromesnail
@jeromesnail 4 года назад
I love the way Next.js handle SPA, SSG and SSR seamlessly. To me it's much more simple than Gatsby...
@happysloth91
@happysloth91 4 года назад
I don't think you need to import React, Next js does that for you. Unless ofc you need sth like useEffect, ...
@atsourno
@atsourno 3 года назад
why would you need useEffect on Next.js?
@thefakequake
@thefakequake 3 года назад
@@atsourno if you want to fetch a resource/send a request client side.
@sophiasminion7279
@sophiasminion7279 4 года назад
I definitely want more nextjs content. I have a cra that I want to convert to a ssr app.
@sundaybackpacker1482
@sundaybackpacker1482 4 года назад
Great job! I look forward to the next tutorials about Next.js !
@AdrianTwarog
@AdrianTwarog 4 года назад
Very nice, I was planning to check out NextJS. Currently just spitting out a CRA app and that's probably not a good idea.
@HaNdTriXo
@HaNdTriXo 4 года назад
Thanks for the awesome video! Since getStaticProps & getStaticPaths are async function you can actually use await fs.promises.readFile(...) this won't block the event loop.
@myke_roly
@myke_roly 4 года назад
Awesome!!! Im starting ssd with next.js and your video helpe me much!!
@jantomotulo3754
@jantomotulo3754 4 года назад
Thank you, i have better understanding what ssg is. Salut!
@adrienblanc4662
@adrienblanc4662 4 года назад
Great video, would love more about Next.js, have a nice day
@AlejandroVivas
@AlejandroVivas 4 года назад
Amazing video, very clear and easy to follow. Thank you!
@adamkenton2585
@adamkenton2585 4 года назад
Can you show how to implement a dark mode in a next js app from scratch ?
@landonwjohnson
@landonwjohnson 4 года назад
This is going to be a game changer! I have been waiting for this.
@sprioleau
@sprioleau 3 года назад
More Next.js content, please.
@fev4
@fev4 4 года назад
f'ing perfect timing man, thanks again
@sky_kryst
@sky_kryst 4 года назад
Just started learning TypeScript today in the post quarantine world. What do you use TS or ES lint for typescript? Does ESlint have good enough linting for TS?
@bawad
@bawad 4 года назад
use eslint, tslint is deprecated
@user-dc2kn7lc6v
@user-dc2kn7lc6v Год назад
thank you for the video, clear
@SowedCastelli
@SowedCastelli 4 года назад
As always, thank you Ben
@eduludi
@eduludi 4 года назад
Great video, Ben! Thanks for it. Do you know if is possible to do incremental builds/exports? I mean, in case you have new or updated posts, only these will be generated, leaving untouched the rest. I think that will be really helpful when you have a lot of posts.
@bawad
@bawad 4 года назад
I don't think so
@irhamputra3666
@irhamputra3666 4 года назад
I don't know if Gatsby user are tempting with this cool feature from Next.js :D but imo they will stick to Gatsby because Gatsby has a lot of cool plugins
@jeresalem
@jeresalem 4 года назад
The only reason why I've stayed away from Gatsby - too much bundled in.
@zain5962
@zain5962 4 года назад
Please make a complete course on next.js
@andreaskarz
@andreaskarz Год назад
Very cool - thank you
@martinvang2153
@martinvang2153 4 года назад
Hi Ben - thanks for another awesome video. I'm building a portal that has both public content and content behind user login. I was thinking if I use next.js SSR for the public content and then next.js SSG to serve a react CSR SPA (normal react app served using SSG). Is this a stupid approach and/or is there a better way to have use SSR and CSR on the same portal? PS: I'm completely new to next.js. My motivation is to have better SEO for the public pages by using SSR and then minimize the complexity of the private pages by using standard react (CSR) for those.
@jpslr-86
@jpslr-86 4 года назад
Ben great content as always. ty! . Now, If a client comes to you for a website would you say next Ssg is read for production sites?
@bawad
@bawad 4 года назад
yeah
@YouWatchGames
@YouWatchGames 4 года назад
Really strange my html does not render correctly. If for example I put an inside the dangerouslysetinnerhtml, it renders it as plain text but when I click on inspect on chrome it shows the button tag.
@kamilzielinski504
@kamilzielinski504 4 года назад
Great vid, thanks. How would it look like for hybrid static + client (no ssr) REST API call app ? Should I simply call the REST API dynamically and add the content? Is it a good practice or there is some more Next.js magic?
@madukomablessed4712
@madukomablessed4712 4 года назад
Hey Ben, great content. Could you please do a new tutorial series for react native? I'd love that. Thanks
@Passion_Life
@Passion_Life 4 года назад
Great video! Could you talk more about how to deploy server-side-render Next JS app to Netlify? Thanks
@bawad
@bawad 4 года назад
you can't
@vladsvyrydonov1793
@vladsvyrydonov1793 4 года назад
like your Videos, next.js is very interesting, please more
@dhruvmaniya7149
@dhruvmaniya7149 Год назад
is SSG only works on dynamic paths? And if it is not only for dynamic paths then Is this getStaticPaths and getStaticProps functions renders when component render or Next renders it when any pages of app renders if it is in different components too, suppose I want to generate all components of pages folder and my SSG functions are in Pages > movies.js component then will it work? will it generate all of my pages? or it will generate only when movies.js component renders?
@jakespeakz
@jakespeakz 4 года назад
please do a firebase fetching data with firebase.database()
@georgewilkins5003
@georgewilkins5003 4 года назад
Ben goes full Texan 11:33
@Skia_
@Skia_ 4 года назад
my Lebanese homie is back at it again
@nix6030
@nix6030 3 года назад
How if i want to .map the entire .md content for the sake of listing the entire blog so user can read the title, description before go to the blog ???
@KarahannAe
@KarahannAe 3 года назад
When I open the exported html files on the browser they dont work properly. I don't understand why do we have to serve them with "npx serve out" if they are static files?
@rajuahammad7554
@rajuahammad7554 3 года назад
Hi, I face this error prnt.sc/vwbto1. how can I solve it?
@jzmmm
@jzmmm 4 года назад
Hey Ben, good video. Just a quick question, what are the manifest files for in the export static html files? Is there any way to remove them?
@apayrus
@apayrus 4 года назад
Thank you. So clear and helpful. I like and describe :)
@MeziIroaga
@MeziIroaga Год назад
Hi Ben, thank you for the video! I am trying to export the static HTML page so I can use it elsewhere, but for some reason my out folder doesn't contain the html file itself, only the other files. Is there a way to fix this problem?
@dilsmatchanov
@dilsmatchanov 4 года назад
but what if I have lots of posts and when I wanna add/edit/delete a post, should I rebuild the whole project again?
@bawad
@bawad 4 года назад
yes if that gets to the point where it is too slow, that's where you might want to generate the pages at runtime when requested instead of at build time
@zomakaja
@zomakaja 4 года назад
Excellent video, keep it up
@myhendry
@myhendry 4 года назад
Hi Ben, now that Nextjs has static site generation, wouldn't that be the same as Gatsby? Nextjs does have an extra implementation in the form of dynamic server side rendering though. Personally, i find Gatsby easier to implement static sites with its in-built GraphQL and plugins
@mdjahidulislam9205
@mdjahidulislam9205 3 года назад
Ok its static site i understood thanks. But after deployment. What if i added a new post on my server. Then should i need to rebuild & deploy it again?
@DBAaron
@DBAaron 3 года назад
If I build a SSG website that allows users to upload blogposts via a form and then create markdown files, how will the website update? Do I need to deploy every minute?
@gurkaransingh449
@gurkaransingh449 4 года назад
Ohk so my website (webapp) view is going to be somewhat different for everyuser (site can be modified and have plugins) so should i use SSR or CSR?
@kademmohammed6836
@kademmohammed6836 3 года назад
Thanks so much
@CrazyFanaticMan
@CrazyFanaticMan 4 года назад
which extension is he using to get his terminal to look like that? if anyone knows the answer, I'd really appreciate it
@randalvc
@randalvc 4 года назад
Once I have a million markdown files, and I added a new markdown file, does the compilation process include the million other markdown files again?
@gabbrissimo
@gabbrissimo 2 года назад
Can i ask you guys which hosting are you using for a nextjs app?
@joseandkris
@joseandkris 4 года назад
Awesome video, just when I wondered how to do this... (RU-vid knows to read minds I guess now)
@jacobmedure7038
@jacobmedure7038 3 года назад
import marked from "marked" not working for me
@dev__adi
@dev__adi 4 года назад
great video, please make a part 2 of it showing how to use SSG with MDX
@bawad
@bawad 4 года назад
twitter.com/benawad/status/1242475931173883904
@marialopez1062
@marialopez1062 3 года назад
I have a couple questions about nextjs and if anyone with experience can answer them I would appreciated it. I know next js can be used for front end and back-end but what I don't understand is what's the benefits of using it for front end only with a django or php backend.
@theuniverse685
@theuniverse685 4 года назад
Excellent! I was reading the Next.js docs, but I didn't understand a thing. What if I have an e-commerce, and this e-commerce has thousands of products, but I need to generate those products pages for SEO, which approach is good for it?
@bawad
@bawad 4 года назад
this approach would work, I think thousands is doable at build time
@theuniverse685
@theuniverse685 4 года назад
@@bawad So will you iterate into thousands products fetched from an api? This seems weird hahaha
@murillomfs
@murillomfs 4 года назад
Nice content. I’m working on a blog with next.js right now and I’m having some problems to deploy it in other folders than the root folder of my FTP. You something that can help me?
@bmasseybrannen
@bmasseybrannen 4 года назад
I am doing well today
@Sankaritarina89
@Sankaritarina89 3 года назад
quick question: if you would have like a hundred blog posts in .md form, and you would want to display the latest 5 posts on your /home... how would you know which ones are the latest? My idea would to add a "published" parameter to each .md and then when you map through the files in home's getStaticProps, just check that parameter. Is that a good idea? or how would you do it?
@erfer
@erfer 3 года назад
Maybe sort the items by created and just grab the first 5?
@Sankaritarina89
@Sankaritarina89 3 года назад
@@erfer yes, that was my idea too. It works as intended
@erfer
@erfer 3 года назад
@@Sankaritarina89 another way could be to write each file name to a separate text file and then just read the last/first 5 lines of the file - this way you don’t need any sorting
@Sankaritarina89
@Sankaritarina89 3 года назад
@@erfer that sounds good too. My situation is that I grabbed all the Blogposts from my wordpress and saved them as individual JSON files. They already have the publish date, so that makes it easy. I already got a working prototype for my blog with static next js last night. All good. Next js is amazing. I had not used the static feature before but it is amazing and so easy!
@hardikmodi8234
@hardikmodi8234 4 года назад
great video
@kenwanjohi5128
@kenwanjohi5128 4 года назад
this is great
@89lakaganth
@89lakaganth 4 года назад
Can we get more of Next.js please...
@centereddev
@centereddev 4 года назад
Awesome! How would you go about deploying a site that has both SSR and SSG?
@bawad
@bawad 4 года назад
I would use Zeit Now also known as Vercel
@centereddev
@centereddev 4 года назад
@@bawad Thanks for the reply! Unfortunately, I'm not sure that's an option for me. We have to use AWS and/or Kubernetes at my company.
@blasttrash
@blasttrash 4 года назад
what happened to vim or neovim? r u not using those? I see that u have vscode vim. I am new to vim and wanted to learn vim, but did u stop using it altogether? was there some problem with it? I am not sure if I should learn vim, hence the question
@bawad
@bawad 4 года назад
is vim worth learning? yes do I still like VSCode? yes, which is why I mix them
@fryxo
@fryxo 4 года назад
How to do it with a variable folder as [slug] then the folder containing [slug].js
@fryxo
@fryxo 4 года назад
Because I am not able to import fs in the [slug].js file
@yimingli224
@yimingli224 4 года назад
Why I can not see node_modules in your folder structure ?
@bawad
@bawad 4 года назад
because I hide it
@crazier192
@crazier192 4 года назад
Thanks for the introduction. Could you help answer why next.js has so many labor work? I mean you have to do all kind of stuff. In my perspective, next.js should provide all the things you've done in this video. Users just need to add more md files.
@bawad
@bawad 4 года назад
give gatsby a try if you want that
@crazier192
@crazier192 4 года назад
@@bawad I think you misunderstood my question. I don't say next.js is not good. I just want to know why next.js choose this way (labor work in my opinion), what is the benefit of doing it?
@unev
@unev 4 года назад
Hi, Ben. Any thoughts why react devtools are unable to parse my next.js project?
@bawad
@bawad 4 года назад
no idea
@OBLIVIOUSKARI
@OBLIVIOUSKARI 4 года назад
Thanks! Do you know how to use Apollo client in this?
@bawad
@bawad 4 года назад
github.com/zeit/next.js/tree/canary/examples/with-apollo
@maxiequa567
@maxiequa567 4 года назад
How can you use the front matter title to make cleaner links? using the filenames makes the-slugs-look-ugly. :)
@bawad
@bawad 4 года назад
slugs usually look like that, but you could make the slug whatever you like by parsing the front matter info in getStaticPaths
@maxiequa567
@maxiequa567 4 года назад
@@bawad Decided on this solution, might be of interest to others: // Function to convert string to Title Case const titleCase = (str) => str.replace(/\b\S/g, t => t.toUpperCase()) // Wrap the slug in the function and remove the filename hyphens // JSX slugs.map change {slug} to: {titleCase(slug.replace('-', ' '))} Result: clean titles from dirty slugs. lol Feedback/criticism welcome :)
@dilsmatchanov
@dilsmatchanov 4 года назад
Is it considered to be JAM stack?
@fr3fou
@fr3fou 4 года назад
yes
@INKWEON7269
@INKWEON7269 4 года назад
Thanks~!! How to add image in .md file~?
@jonmichalak7346
@jonmichalak7346 4 года назад
does this play nice with ZEIT's now/have you ever used now.sh??
@bawad
@bawad 4 года назад
yes and yes
@JonathanWilke
@JonathanWilke 4 года назад
Next.js and Zeit now always work perfectly together, because they are both built by the same team.
@jonmichalak7346
@jonmichalak7346 4 года назад
@@bawad thanks for the reply (many 'tubers don't). love the channel
@b1chler
@b1chler 4 года назад
Did u try it with TypeScript and GraphQL? They added Generics in next version 9.3.1... github.com/zeit/next.js/issues/11033
@bawad
@bawad 4 года назад
I haven't yet
@KozaKrisz
@KozaKrisz 4 года назад
What about MDX? :-)
@bawad
@bawad 4 года назад
gist.github.com/benawad/20c6c8f21dced3a31401c8eb750f9f62
@CodewithFemi
@CodewithFemi 4 года назад
Here's how you deploy Next.js (React framework) on Azure Static Web App Service ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-LbUP8VZFfuU.html
@tenminutetokyo2643
@tenminutetokyo2643 4 года назад
Can you do one on Yarn and now to use it.
@angshu7589
@angshu7589 3 года назад
You writing JS is hurting my eyes. How are there no ".ts" files?
@dailymeow3283
@dailymeow3283 2 года назад
Anyone keep having this lame ad with boobie girl "So you wanna be a frontend engineer at google " 🤦‍♂️
@someone-on-earth
@someone-on-earth 4 месяца назад
yes, everytime!!
Далее
How to Roll Your Own Auth
13:05
Просмотров 104 тыс.
How NextJS REALLY Works
28:25
Просмотров 146 тыс.
5 Reasons To Use Next.js Over Plain React
14:50
Просмотров 36 тыс.
The Story of Next.js
12:13
Просмотров 573 тыс.
When Should You Use Gatsby?
9:06
Просмотров 152 тыс.
Next.js 13 SSG, SSR & ISR | Nextjs 13 tutorial
22:01
Просмотров 52 тыс.
SSG vs SSR Explained in 10 Minutes (For Beginners)
8:52
NextJS 12.1 SSR & SSG: Everything you need to know
31:18
Next.js Tutorial For Beginners
52:35
Просмотров 42 тыс.