Replies: 2 comments 1 reply
-
Part of this could also include a dynamic assetPrefix, which you can set on runtime, so you can set a CDN host for e.g. the production deployment, but not for the test/acceptance/development deployment, while using the same docker build. Instead of having to create a custom pre-run script to replace this assetPrefix, like: #18301 (comment) |
Beta Was this translation helpful? Give feedback.
1 reply
-
Part of this could also include the customisation of |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Background
Currently NextJS supports 2 kind of assetPrefixes; relative & absolute (but only the host).
If you use a relative url (e.g.
/custom-prefix
), the client uses the current host + the relative path to fetch the bundles & the server hosts the bundles on the relative path.If you use an absolute url, but only the host, (e.g.
https://cdn.website.com
) it fetches the bundles from the new host from the root & the server hosts the bundles on the root pathIssue
However, if you use an absolute url WITH a path. (e.g.
https://cdn.website.com/custom-prefix
) The client fetches the bundles from the new host + path, while the server serves the bundles from the root (in stead of the path of the absolute url). Resulting in a 404 for fetching the bundles. (could even be considered a bug?)-> Client call
FETCH https://cdn.website.com/custom-prefix/_next/static/<bundles>
-> Server serves bundles on
<internal_url>/_next/static/<bundles>
(missing path prefix from absolute url)Proposal
Method 1
For backwards compatibility assetPrefix can stay a string.
-> If the assetPrefix is a relative url, it can be used by the client & server.
-> If the assetPrefix is a absolute url, the client uses the full absolute url, while the server only uses the path.
Method 2
Client uses host + path, while the server uses only the path. Easier than having NextJS to parse. Maybe only use the host in production builds as it makes no sense to point to a deployed build when running locally.
Note
The above 2 methods keep the path in sync between the client & server, but we could let the consumer customize even more.
This however, does give NextJS' assetPrefix functionality more complexity as a consumer could mismatch paths easily, but does give you more customisation if you have some routing in front of your NextJS app.
Method 3
Method 4
Method 5
Beta Was this translation helpful? Give feedback.
All reactions