Unverified Commit 327488da authored by Thomas Boyt's avatar Thomas Boyt Committed by GitHub

Improve documentation of CDN asset paths (#25531)

I've been working on adding CDN support to my Next.js app and was very surprised to find that the `assetPrefix` did not turn `/_next/static/chunks/sha.js` into `$assetPrefix/chunks/sha.js`, but instead `$assetPrefix/_next/static/chunks/sha.js`. Hopefully this change to the documentation will make this behavior much more clear to future users.

I've also incorporated a warning against uploading the entire `.next` folder to a CDN, as I saw @timneutkens note in a discussion here: https://github.com/vercel/next.js/discussions/11622#discussioncomment-3779

## Documentation / Examples

- [ ] Make sure the linting passes
parent 9b75b9ba
...@@ -24,9 +24,21 @@ module.exports = { ...@@ -24,9 +24,21 @@ module.exports = {
} }
``` ```
Next.js will automatically use your asset prefix for the JavaScript and CSS files it loads from the `/_next/` path (`.next/static/` folder). Next.js will automatically use your asset prefix for the JavaScript and CSS files it loads from the `/_next/` path (`.next/static/` folder). For example, with the above configuration, the following request for a JS chunk:
Asset prefix support does not influence the following paths: ```
/_next/static/chunks/4b9b41aaa062cbbfeff4add70f256968c51ece5d.4d708494b3aed70c04f0.js
```
Would instead become:
```
https://cdn.mydomain.com/_next/static/chunks/4b9b41aaa062cbbfeff4add70f256968c51ece5d.4d708494b3aed70c04f0.js
```
The exact configuration for uploading your files to a given CDN will depend on your CDN of choice. The only folder you need to host on your CDN is the contents of `.next/static/`, which should be uploaded as `_next/static/` as the above URL request indicates. **Do not upload the rest of your `.next/` folder**, as you should not expose your server code and other configuration to the public.
While `assetPrefix` covers requests to `_next/static`, it does not influence the following paths:
- Files in the [public](/docs/basic-features/static-file-serving.md) folder; if you want to serve those assets over a CDN, you'll have to introduce the prefix yourself - Files in the [public](/docs/basic-features/static-file-serving.md) folder; if you want to serve those assets over a CDN, you'll have to introduce the prefix yourself
- `/_next/data/` requests for `getServerSideProps` pages. These requests will always be made against the main domain since they're not static. - `/_next/data/` requests for `getServerSideProps` pages. These requests will always be made against the main domain since they're not static.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment