Home >Web Front-end >JS Tutorial >Mastering Next.js: My Journey from SSG to SSR Through Trial and Error
Hi Guys! In this blog i wanna share with you the next new project that I've been working on for a good amount of time. It really takes me back to when i started my journey with MERN stack when i used to struggle in every project that I made but after having gone through all that hardships I can still say that getting stuck on some topics still freaks me out a little bit.
I want to share with all of you about the difference between SSG and SSR.
I was doing a minor project of making a blog site and i wanted to generate the blogs on the build time but It was not genrating and after 1 week of searching and wandering on internet learning about the difference I finally understood what is the difference.
Next.js is a powerfull React framework developed by vercel. It has several built-in features to enhance development and user experience.
Some of the features are:
SSG generates static HTML pages at the build time. The content is pre-rendered which means it doesn't change until you rebuild the site.
It is best for pages that doesn't change too frequetly like the Marketing pages or documentation which doesn't change too frequently.
It basically is generated during the build time and are static so they load extremely quickly.
In this to get the Dynamic path that you want to render on build time you can use the getStaticParams. You can read more about this here. Link
SSR generates HTML pages on each request. The server renders the HTML dynamically for each incoming request. It is best for pages that need to be dynamic and up-to-date on every request. This includes user dashboards, news feeds, and other content that changes frequently or is user-specific.
Since HTML is generated on each request so it is slower than SSG but it ensures that the content is always fresh and up-to-date.
My journey with Next.js, SSG, and SSR has been filled with learning opportunities. Each error and challenge has deepened my understanding and improved my problem-solving skills. I encourage you to experiment with both SSG and SSR in your projects to see how they can best serve your needs.
Thank you for reading! I hope my experiences help you in your Next.js journey. Feel free to share your own experiences or ask questions in the comments below. Let's continue learning and growing together as a community. Happy coding!
The above is the detailed content of Mastering Next.js: My Journey from SSG to SSR Through Trial and Error. For more information, please follow other related articles on the PHP Chinese website!