> For the complete documentation index, see [llms.txt](https://docs.userlane.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.userlane.com/deployment/rollout/the-userlane-snippet/use-subresource-integrity.md). Agents can also search and read this documentation through its [MCP server](https://docs.userlane.com/~gitbook/mcp).

# Use Subresource Integrity

How to load the Userlane snippet with Subresource Integrity so the browser only runs an unmodified userlane.js.

Load the Userlane script with Subresource Integrity[^1] (SRI), so the browser runs userlane.js only if it matches the version Userlane released.

{% hint style="warning" %}
**Before you start.** You need the snippet installed in the application and a developer who can change its code. SRI works in Edge 79+, Firefox 60+, Chrome 70+, and Safari 12+.
{% endhint %}

## How it works

The secure snippet asks Userlane over HTTPS for the current file name and integrity hash[^2], then loads userlane.js with that hash. The browser checks the file against the hash and refuses to run a changed file. Because the hash changes with every Userlane release, the secure snippet fetches it on each page load, and it must never be cached.

## Replace the loader

Replace the load part of your snippet with the secure version below. Your `identify` and `init` commands stay the same.

```javascript
(function (i, s, o, g, r, a, m) {
    i['UserlaneCommandObject'] = r;
    i[r] = i[r] || function () {
        (i[r].q = i[r].q || []).push(arguments);
    };
    var req = new XMLHttpRequest();
    req.open("GET", "https://api.userlane.com/integrity/artifacts/main", false);
    req.send();
    var resp = JSON.parse(req.response);
    a = s.createElement(o), m = s.getElementsByTagName(o)[0];
    a.async = 1;
    a.src = g.replace("userlane.js", resp["entryPoint"]);
    a.integrity = resp["integrity"];
    a.crossOrigin = "anonymous";
    m.parentNode.insertBefore(a, m);
})(window, document, "script", "https://secure.userlane.com/userlane.js", "Userlane");

Userlane('init', 'property_ID');
```

{% hint style="success" %}
**Result.** Userlane loads as before, and the browser blocks a modified copy of userlane.js.
{% endhint %}

## Troubleshooting

| Problem                                | Cause                                                                      | Fix                                                                                                                            |
| -------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| Integrity error in the browser console | The hash was cached or the loader code was edited                          | Fetch the hash on every page load and restore the loader code above                                                            |
| Userlane is blocked from loading       | The application's Content Security Policy doesn't allow the Userlane hosts | Add the hosts listed in [Environment prerequisites](https://docs.userlane.com/deployment/rollout/environment-prerequisites.md) |

## Related articles

{% content-ref url="/pages/JxxDQNfBXhCBW2L8uKRW" %}
[Install the snippet](https://docs.userlane.com/deployment/rollout/the-userlane-snippet.md)
{% endcontent-ref %}

{% content-ref url="/pages/GIfweTU9uzaVjAhuIhz4" %}
[Use a client token](https://docs.userlane.com/deployment/rollout/the-userlane-snippet/use-a-client-token.md)
{% endcontent-ref %}

## FAQ

<details>

<summary>Is Subresource Integrity required for the snippet?</summary>

No. Subresource Integrity is optional.

</details>

<details>

<summary>Can the integrity hash be cached?</summary>

No. The integrity hash changes with every Userlane release.

</details>

[^1]: Subresource Integrity (SRI) is a browser check that refuses to run a script unless it matches a known hash.

[^2]: An integrity hash is a fingerprint of the exact userlane.js file that Userlane released.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.userlane.com/deployment/rollout/the-userlane-snippet/use-subresource-integrity.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
