Duc Mai

Full stack developer

2022-08-11

real life problems with nextjs ssg and production sites

real life problems with nextjs ssg and production sites

I have been using nextjs for a couple of my hobby projects and it has worked fine until I had a chance to use nextjs in a website for my company. This time it reveals several troubles with nextjs deployment when we do it our selves.

What

Nextjs is a great framework for those who develops with react and vercel is a best fit option too for nextjs. But to use nextjs in a self hosting environment and SSG you will suffer two big pains that challenge your mindset about development.

Problems

  • Deployments with docker
Normally a deployment chain will build an image from the source code then we test on that image, once the test is done we will release the same image. That will make sure we release what we have tested. However with nextjs ssg because the static html files are built at build step so you basically need to have multiple images for environment. This will cause what you have tested maybe not exactly what you will release. This challenge requires you to change your view on one image for all environments.
  • Decide which content to build
You need to decide in build step which content you are going to build. This decision will affect on your build time. Imagine if you have thousand pages in your cms then you need to somehow build a part of them and let the rest is generated on the fly. If you want your site is completely static then it will take time to build. This is somehow different with the traditional way that generate content on the fly.
  • Rebuild when content changes
Since you are using SSG so you will need to regenerate your content every time you make a change to your content. For example if your content is from a cms then you will need to trigger a static build in nextjs. I can see two options so far: one is to rebuild and deploy the whole package and the other is to call a special link on every front-end server to regenerate the static files. Each has its own downside. I have come to a conclusion which one is better.
nextjsreact

About me

How I describe about myself

A developer cares about climate changes and environments

A full stack js developer

A developer is interested in cloud technologies

A challenge lover

Language:

English, Swedish, Vietnamese

Email:
mrducvmv88@gmail.com
LinkedIn:
Duc Mai
Twitter:
Duke Mai
IndieHackers:
Duc Mai