Skip to content
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

Add multiple cdn #6982

Closed
wants to merge 9 commits into from
28 changes: 27 additions & 1 deletion src/content/docs/en/reference/configuration-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,17 @@ Specifies the directory in the build output where Astro-generated assets (bundle

<p>

**Type:** `string`<br />
**Type:** `string | Record.<string, string>`<br />
**Default:** `undefined`<br />
<Since v="2.2.0" />
sarah11918 marked this conversation as resolved.
Show resolved Hide resolved
</p>

Specifies the prefix for Astro-generated asset links. This can be used if assets are served from a different domain than the current site.

<p>
**If this value is a `string`,**
</p>

For example, if this is set to `https://cdn.example.com`, assets will be fetched from `https://cdn.example.com/_astro/...` (regardless of the `base` option).
You would need to upload the files in `./dist/_astro/` to `https://cdn.example.com/_astro/` to serve the assets.
The process varies depending on how the third-party domain is hosted.
Expand All @@ -512,6 +516,28 @@ To rename the `_astro` path, specify a new directory in `build.assets`.
}
```

<p>
**If this value is a `Record<string, string>`,**
</p>

If your static files are served from different CDNs, you can configure Astro to use unique prefix paths for each CDN based on the filetype requested.

For example, if the static file is a `.js` file, it will be served from `https://js.cdn.example.com`. If it is a `.css` file, it will be served from `https://css.cdn.example.com`. All other assets will be served from `https://cdn.example.com`.

```js
{
build: {
assetsPrefix: {
'js': 'https://js.cdn.example.com',
'css': 'https://css.cdn.example.com',
'defaultAssetsPrefix': 'https://cdn.example.com'
}
}
}
```

The object key is the file extension, and its value is the CDN prefix path. You can set the default values of all other files by setting the value of `defaultAssetsPrefix`. If `defaultAssetsPrefix` is not set, when the file extension is not found in the `assetsPrefix` object, it will be set to the empty string `''` by default.

### build.serverEntry

<p>
Expand Down
Loading