-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prebuild JS Bundles for CDN #3284
Comments
That's exactly what That's also why Next.js custom config support |
Ah gotcha. I've got some other bad config emitting a build and dist folder which confused me. Thanks for clarification! |
Not sure what I'm doing wrong, but this doesn't seem to be working for me. The browser is requesting files from urls like
But these paths do not show up in the output of
So what am I supposed to be uploading to the CDN? |
@pcardune You don't need to upload anything.
So,
This is the same thing we do for https://zeit.co. In our case, |
Yes, I'm familiar with using a CDN as a proxy to your application servers. But I think it is still useful to be able to get all the assets in static file form for the following reasons:
|
We're currently looking into uploading assets to a bucket as well, it seems like we'll need to generate the mappings ourselves. It doesn't seem like using the application servers as the origin would work though because of the versioning requirements, especially if the application servers are behind a load balancer, and rolling deploys means that multiple versions can coexist. |
Plus one. Can we get this issue reopened? |
Next.js detects a BUILD_ID change and reload the page to use the new built files. So if an user access to a Next.js app and start navigating the page, then the developer build a new version, the internal BUILD_ID will change, if the user try to navigate to another page client side Next.js will detect the mismatch of the BUILD_ID and do a page reload, then it will download the new built files, so you don't need to have two versiones coexisting, user of the old version will be forced to load the new bundles. |
Google cloud cdn doesn’t support remote origin and uses google storage. Is it too much to ask that next outputs truly static bundles. Seems a bit needless that static file requests run through nodejs to begin with. |
@sergiodxa If I deploy a new version, rolling update is started. At that time, a user requested my app, and the LB send the request to a new version. But this time, If the LB send the reqeust of CDN to the old version instance, CDN will receive a response 404. because the old one doesn't have new assets. So, I will build my next.js app, make BUILD_ID directory in my origin (like S3) and upload files in dist to BUILD_ID directory. |
Exactly and would be the case for some forms of AB testing where you deploy two versions to different groups of users |
@jsnick good summary. We’ve already implemented exactly that at my workplace. It works well so far. Not sure if there’s interest for an open source contribution |
Just to follow up on this, we were able to get this working with rolling deploys on S3 (ECS with CloudFront sitting in front of the services and S3). All we really need "custom" on the Next side is Dockerfile:
next.config.js:
You need to set a behavior on your CloudFront distribution pointing |
I set
It's added following script
I uploaded I'm able to get main.js bundle with 200 OK but getting 400 Error for other pages. You can see there is build number in the path but there is not such path in the |
The Is it possible to just configure assetpath, build, and host the |
Would it be possible for
next build
to prebuild all js bundles from pages and spit them out so they can be uploaded to the cdn? I can seenext export
however I still want the server for the initial render but also want to leverage a CDN for my js assets.The text was updated successfully, but these errors were encountered: