Skip to main content

How the JS Tag Works

This page covers what you need to know about nxis.js for security and caching after you install it: which hosts your token works on, what the script does and doesn't do to your page, what it requests and how those responses are cached, and what to allow in a Content Security Policy.

The script loads async, so it never blocks HTML parsing or rendering, and it's about 11 KB gzipped.

What happens on a page view​

If your token uses ssr mode (you render JSON-LD on the server with the SSR SDK), the script skips the fetch and the injection, and only registers tools from the JSON-LD already in your page. You choose the mode when you issue the token.

Which hosts a token covers​

The tag token is public by design: it sits in your page HTML and is safe to commit. What stops another site from using it is its list of hosts. When a browser loads nxis.js, the CDN compares the requesting page's host (from the request's Origin or Referer header) with each host in the token's domains list:

  • Exact host match. example.com doesn't cover docs.example.com, and it never matches by substring (example.com.evil.tld is refused). List each subdomain you serve.
  • www. is the same host. www.example.com and example.com match each other.
  • Scheme and port are ignored. https://example.com:8443 reduces to example.com.
  • No wildcards. Issuing a token with any entry containing * (including *.example.com and * itself) is refused, with a message asking you to list each host instead.
  • Your site's own host is always included, and a token holds at most 10 hosts.

Local development and previews​

There's no special case for local addresses. On http://localhost:3000 the tag behaves exactly as on production, as long as localhost is in the token's domains. One localhost entry covers every port. 127.0.0.1 is a different host and needs its own entry.

WebMCP tools need a secure context. localhost and 127.0.0.1 count as secure over plain HTTP, but a LAN address or a .local name over http:// doesn't, so on such a page no tools are registered in browsers without native WebMCP.

Deploy previews have per-build hostnames, so the tag refuses them. That's expected; test locally or in production.

When the token is refused​

The script URL always answers 200 OK with JavaScript, never an error page. When the token is missing, malformed, expired or not valid for the host, that JavaScript is a single console.warn and nothing else:

Console messageCause
Nxis: Missing authorization tokenThe token query parameter is missing.
Nxis: JWT Error: …The token is malformed or has expired.
Nxis: Domain UnauthorizedThe page's host isn't in the token's domain list. Common on localhost when it isn't listed, and on deploy previews.
Nxis: Account RevokedThe account behind the token is no longer active.

The tag can't break your page with an HTTP error or a script error. When it's refused, you get no structured data and no tools.

What it does to your page​

When there's data for the page, the script appends this to the end of <head>:

<!-- Nxis.ai -->
<script type="application/ld+json">{ … }</script>
<!-- End Nxis.ai -->

It also registers the Schema.org Actions in your page's JSON-LD as WebMCP tools on document.modelContext. Registering a tool doesn't touch your forms: a form is filled and submitted only when an agent calls its tool, and then through requestSubmit(), so your own validation and submit handlers run.

It doesn't:

  • set cookies, or write to localStorage or sessionStorage
  • change your visible DOM, styles or existing markup (your own JSON-LD is left alone)
  • use document.write or load other scripts
  • send analytics beacons from the page
  • add an on-page chat agent (that's the separate Agent Harness, which you add yourself)

What it requests, and caching​

Besides nxis.js itself from https://cdn.nxis.ai, the script makes plain GET requests to https://proxy.nxis.ai for the page's structured data. In ssr mode it requests nothing. Each response carries its own Cache-Control, which the CDN and the browser both honor:

ResponseCache-ControlWhat it means for you
nxis.jsNone setDon't rely on any particular caching of the script.
Finding a page's datapublic, cached for up to a day (max-age at most 86400)A published edit can take up to a day to reach a page a browser or the CDN has already seen. A cached answer is also served if NxisAI is briefly unavailable.
Page datapublic, max-age=31536000, immutableIts URL changes whenever its content does, so a cached copy is never stale.

None of these responses sets cookies, and an agent calling a tool adds no request from the tag: the form submits the way it always does.

Content Security Policy​

If your site sends a Content Security Policy, allow:

  • https://cdn.nxis.ai in script-src
  • https://proxy.nxis.ai in connect-src. Without it, the script still loads, but its requests for the page's structured data are blocked and nothing is added to the page.

Keep the crossorigin="anonymous" attribute and the preconnect from the install snippet.

Checking it on a live page​

  1. In DevTools, open Network and filter by nxis. You should see nxis.js and the structured-data request.
  2. In Elements, look for <!-- Nxis.ai --> near the end of <head>.
  3. In the Console, run await document.modelContext.getTools(). It should list your page's Actions.

If nothing appears, check the Console for one of the messages above.