react-code-dataset
/
next.js
/docs
/01-app
/03-api-reference
/05-config
/01-next-config-js
/crossOrigin.mdx
| --- | |
| title: crossOrigin | |
| description: Use the `crossOrigin` option to add a crossOrigin tag on the `script` tags generated by `next/script`. | |
| --- | |
| {/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} | |
| Use the `crossOrigin` option to add a [`crossOrigin` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) in all `<script>` tags generated by the <AppOnly>[`next/script`](/docs/app/guides/scripts) component</AppOnly> <PagesOnly>[`next/script`](/docs/pages/guides/scripts) and [`next/head`](/docs/pages/api-reference/components/head)components</PagesOnly>, and define how cross-origin requests should be handled. | |
| ```js filename="next.config.js" | |
| module.exports = { | |
| crossOrigin: 'anonymous', | |
| } | |
| ``` | |
| ## Options | |
| - `'anonymous'`: Adds [`crossOrigin="anonymous"`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin#anonymous) attribute. | |
| - `'use-credentials'`: Adds [`crossOrigin="use-credentials"`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin#use-credentials). | |