For AI agents: the complete documentation index is available at https://rsbuild.rs/llms.txt, the full documentation bundle is available at https://rsbuild.rs/llms-full.txt, and this page is available as Markdown at https://rsbuild.rs/config/html/crossorigin.md.
close

html.crossorigin

  • Type: boolean | 'anonymous' | 'use-credentials'
  • Default: false

Set the crossorigin attribute of the <script> and <link rel="stylesheet"> tags.

  • If true is passed, it will automatically be set to crossorigin="anonymous".
  • If false is passed, it will not set the crossorigin attr.

Example

rsbuild.config.ts
export default {
  html: {
    crossorigin: 'anonymous',
  },
  output: {
    assetPrefix: 'https://example.com',
  },
};

After compilation, the <script> tag in HTML becomes:

<script
  defer
  src="https://example.com/static/js/main.js"
  crossorigin="anonymous"
></script>

The <link rel="stylesheet"> tag becomes:

<link
  href="https://example.com/static/css/main.css"
  rel="stylesheet"
  crossorigin="anonymous"
/>
Tip

When this option is enabled, Rsbuild adds the crossorigin attribute to tags that load script and stylesheet files, regardless of whether the resources are from the same origin. If a tag already has this attribute, its value is preserved.

Optional values

crossorigin can be set to the following values:

  • anonymous: Request uses CORS headers and credentials flag is set to 'same-origin'. There is no exchange of user credentials via cookies, client-side SSL certificates or HTTP authentication, unless destination is the same origin.
  • use-credentials: Request uses CORS headers, credentials flag is set to 'include' and user credentials are always included.