Skip to main content
Run your own JavaScript on every page of your site and control which origins your pages may load code from. To send visits to Google Analytics 4, PostHog, Plausible, Umami, Rybbit, DataFast, OneDollarStats or Simple Analytics, use an analytics integration instead, which needs no script.

Custom scripts

Paths here are relative to your selected site root, not necessarily the repository root. Every .js file outside blog/, changelog/, snippets/, public/, styles/ and slots/ runs on every page, whether it’s script.js, a file in a scripts/ folder or a file like analytics.js at the site root. They’re the JavaScript counterpart to custom CSS, while a .js file in snippets/, blog/ or changelog/ is a component you import instead. Files in public/ aren’t automatically loaded as page scripts.
Notra loads every script on every page with defer from your site’s own address, and the scripts run in the order shown above after the browser parses the HTML.
  • These files are plain browser JavaScript rather than modules, so import and export don’t work in them, and you load a library from another host with document.createElement("script") and add that host to allowedOrigins.
  • The build checks the syntax without running your scripts, and a syntax error fails the build with the file name and line number.
  • Your MDX can’t import these files, so for a component, use a snippet in snippets/ instead.
You can use these scripts for custom client-side interactions. If your source needs a bundler, build it yourself as plain browser JavaScript and commit the output as script.js or under scripts/. Notra doesn’t run your repository’s package scripts or serve an arbitrary app build. Keep supporting assets in public/ and check the allowed file types; .html, .mjs and .wasm files aren’t collected. Code that requires dynamic inline scripts or eval won’t work with the default Content-Security-Policy. Adding an origin allows that host, not those execution methods. Choose compatible output or host the app separately rather than disabling the policy to make a bundle run.
scripts/external-links.js
With the c15t cookie banner on, list tracking scripts under integrations.c15t.scripts so they wait until a visitor allows them. Scripts you don’t list keep loading on every page.

Content-Security-Policy

Notra builds a Content-Security-Policy header for every page from your repository, and it decides where scripts can load from and which servers they can connect to.
  • Scripts can come from your site, the analytics integrations you turned on and your allowedOrigins. Notra hashes every inline script that was on the page at build time into the policy, so the browser blocks any inline script injected later.
  • Connections from fetch, beacons and WebSockets may go to your site, your integrations, your c15t backend and your allowedOrigins.
  • The policy doesn’t limit images, styles, fonts, videos and embeds, so posts can still show images and videos from anywhere.
If your custom scripts or components load code from another host or call an API, add that origin:
blog.json
Origins must start with https:// or wss:// and have no path, and https://*.example.com covers every subdomain. A wss:// origin only allows connections rather than scripts, and you can list up to 32 origins.

WebAssembly

Animation runtimes like Rive compile WebAssembly, which the policy blocks by default. Allow it with webAssembly:
blog.json
This adds 'wasm-unsafe-eval' to the policy. JavaScript eval stays blocked. Put the .wasm and .riv files in public/ so they load from your site, or add the runtime’s CDN to allowedOrigins. To turn the policy off, set contentSecurityPolicy to false:
blog.json
If a script doesn’t run, open your browser’s developer console, where each request the policy blocked shows the origin you need to add to allowedOrigins.
Last modified on November 8, 2026