Skip to content

Instantly share code, notes, and snippets.

@simonespa
Created November 25, 2025 09:55
Show Gist options
  • Select an option

  • Save simonespa/65f02b0f07074da518cb652f9378bd66 to your computer and use it in GitHub Desktop.

Select an option

Save simonespa/65f02b0f07074da518cb652f9378bd66 to your computer and use it in GitHub Desktop.
Next.js build ID forr _next/data/

Next.js

When you use a next/link to navigate to another route, and that upcoming route has a getServerSideProps method implemented, Next.js will send an API request to the server, which will run getServerSideProps and return a JSON containing the result. You can read about this in Next.js docs here. That resulted JSON fetch request data is used to render the upcoming route. Those data fetch requests have a path that looks like this: _next/data//.json.

The problem with that for our context — to be able to run multiple Next.js apps on same domain without base url prefix — is that Next.js doesn't give us a way to control this path. Which is to say there's no data fetch request path URL prefix which Next.js gives as a configuration option. Because of that we have a hard time finding a distinguishing factor for data URLs for multiple apps.

Remember that the data fetch url looks like _next/data//<route_slug>.json. If we could have a way generate unique for all our apps, we could use that and write a re write rule at load balancer level to distinguish the request between multiple Next.js apps. By default the is a random id generated by Next.js build process for each build. Thankfully they give us a way to control the build id.

We ended up using a package called next-build-id to configure a custom build id where we gave a app-1- signature and added a re write rule in our load balancer for incoming request host name having app-1 for first app, app-2 for second app and so on and so forth, to solve this.

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment