Attention: Deploying to Vercel automatically configures a global CDN for your Next.js project. You do not need to manually setup an Asset Prefix.
Note: Next.js 9.5+ added support for a customizable Base Path, which is better suited for hosting your application on a sub-path like
/docs. We do not suggest you use a custom Asset Prefix for this use case.
To set up a CDN, you can set up an asset prefix and configure your CDN's origin to resolve to the domain that Next.js is hosted on.
next.config.js and add the
/_next/ path (
.next/static/ folder). For example, with the above configuration, the following request for a JS chunk:
Would instead become:
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.
assetPrefix covers requests to
_next/static, it does not influence the following paths:
getServerSidePropspages. These requests will always be made against the main domain since they're not static.
getStaticPropspages. These requests will always be made against the main domain to support Incremental Static Generation, even if you're not using it (for consistency).