Stagepass

Guide

Content Hashes and a Manifest for Webflow Custom Code

How stagepass build names files after their content, what dist/manifest.json gives you, and why your local swap keeps working with hashed production URLs.

Checked against CLI 2.7.0 loader 2.5.2 macOS
On this page

You deploy a fix, open the client's site, and there it is: yesterday's bug, served fresh from a cache. Or it's fixed for you and still broken for the client, because their browser kept the old file.

Content hashes fix that at the file-name level. Change one byte, get a new file name, and every browser has to fetch it. Stagepass writes them in every production build. This guide shows what the build produces, how to wire the hashed files into Webflow, and why your Stagepass session doesn't care which name production uses.

Why browsers and CDNs keep serving old files

Your JavaScript and CSS live at a URL like https://cdn.example.com/js/main.js. Browsers, CDNs and proxies keep a copy of that URL for as long as the host's cache headers allow. When you upload a new main.js under the same name, nothing tells those caches that the content changed. Some visitors get the new file. Others keep the old one until their copy expires.

The usual workarounds all have a catch:

  • A version query like main.js?v=12. It works, but you have to remember to bump it on every deploy, and a CDN that is set to ignore query strings still serves the old file.
  • Short cache times on the host. Every visitor then downloads or revalidates your files more often, on every site you run that way.
  • No caching at all. Fine for one special script. Wasteful for your main bundle.

A content hash takes the guesswork out: the name changes exactly when the content does, and never otherwise.

What a content hash in a file name is

A hash is a short fingerprint calculated from a file's bytes. Same bytes, same fingerprint. One changed byte, a completely different one.

stagepass build takes the first 8 hex characters of the SHA-256 hash of each built file and puts them into the name. main.js becomes something like main.7db704ee.js, and styles.css becomes something like styles.15c42ab7.css.

The reverse matters just as much. If a build doesn't change a file, its hash stays the same, and so does its URL. Visitors keep their cached copy, which is exactly what you want.

What stagepass build writes to dist/

In a project created with stagepass new, stagepass build runs the project's scripts/build.mjs. After a build, dist/ looks like this:

text
dist/
  main.js               stable copy, swapped in during your session
  main.7db704ee.js      hashed copy for production
  styles.css            stable copy
  styles.15c42ab7.css   hashed copy for production
  manifest.json         hashed names and SRI integrity

manifest.json maps each stable name to its hashed file and a Subresource Integrity (SRI) value, a sha384 hash the browser can check the download against:

dist/manifest.jsonjson
{
  "main.js": {
    "file": "main.7db704ee.js",
    "integrity": "sha384-750R/A17CBBIKHVtYys76qzkruwWH2z9mARHDGhMnq5dBntQmVCDeXgGvwOO4yP4"
  },
  "styles.css": {
    "file": "styles.15c42ab7.css",
    "integrity": "sha384-8U9HYzsHbf55cFZyiWIE29+QPYQ9WO+U5uT/ViFw0TOwM2Fbbb74ZegzRV/nvwrD"
  }
}

Three details are worth knowing:

  • A file in dist/ is rewritten only when its bytes change. Unchanged files keep their name and their timestamp.
  • After writing the new files, the build deletes the hashed files that the previous manifest.json listed and the new one doesn't. It only removes plain <name>.<8 hex>.<ext> files directly in dist/. Everything else stays.
  • The build prints the new manifest entries in the terminal, so you see the new names right away.

Project from an older CLI?

Watch and dev have written only stable files since CLI 2.4.0. If your project was created with an older CLI, run stagepass upgrade. It replaces scripts/build.mjs when the file is still the unmodified scaffold, and asks first in a terminal. A build script you have edited stays as it is, and the CLI tells you what the current scaffold does. See stagepass upgrade.

Wiring hashed files into Webflow

stagepass new prints a footer snippet for Webflow Custom Code. Without a production host in stagepass.json or a GitHub remote, its tags look like this:

html
<script
  data-src="https://YOUR-PRODUCTION-URL/js/main.js"
  data-stagepass="true"
  data-stagepass-path="dist/main.js"
></script>
<link
  rel="stylesheet"
  data-href="https://YOUR-PRODUCTION-URL/css/styles.css"
  data-stagepass="true"
  data-stagepass-path="dist/styles.css"
>

data-src and data-href are the production URLs every visitor loads. data-stagepass-path is the local file your session swaps in. To use hashes, upload the hashed files and point the production URLs at them.

  1. Build the production files.

    Terminalbash
    stagepass build
  2. Upload the new hashed files from dist/ to your host, next to the old ones. Do this before you touch Webflow, so the new URLs already work when the site points at them.

  3. Copy file and integrity for each entry from dist/manifest.json into the tags in Webflow Custom Code.

    html
    <script
      data-src="https://cdn.example.com/js/main.7db704ee.js"
      integrity="sha384-…"
      crossorigin="anonymous"
      data-stagepass="true"
      data-stagepass-path="dist/main.js"
    ></script>
    <link
      rel="stylesheet"
      data-href="https://cdn.example.com/css/styles.15c42ab7.css"
      integrity="sha384-…"
      crossorigin="anonymous"
      data-stagepass="true"
      data-stagepass-path="dist/styles.css"
    >

    integrity is optional. If you set it on a file from another domain, also set crossorigin="anonymous", and make sure your host sends CORS headers for those files.

  4. Publish the Webflow site. Custom Code changes go live only when you publish.

  5. Remove the previous hashed files from the host later, not right away. A page a visitor opened before you published still points at them.

Your session doesn't care about the hash

This is where the Stagepass build workflow pays off. During your own Stagepass session, the loader replaces each tagged production file with the local file named in data-stagepass-path, served from your .sp domain, with a fresh ?_cb= stamp on every page load. Production can point at main.7db704ee.js while you work against dist/main.js, which stagepass watch or stagepass dev keeps current. Everyone else keeps loading the hashed production file.

The loader also removes integrity from the swapped tag during your session, because your local file will never match the production hash. Visitors without a session keep the check.

When you don't need hashes

Hashed names are the right default for your main bundle. The loader has two lighter tools for other cases:

You wantUseWhat visitors get
A new URL for every changed build, with long cachingHashed file names from stagepass buildEach new file once, then from cache
A stable file name you bump by handdata-stagepass-v="12" on the tagmain.js?v=12, until you change the value
One file that must never come from a cachedata-stagepass-nocache on the tag, loader 2.5.0 or laterA fresh ?_cb=<timestamp> on every page view

data-stagepass-v sets the ?v= value for one tag. A data-stagepass-version on the loader tag adds ?v= to every tagged asset, and data-stagepass-v on a tag wins over it.

data-stagepass-nocache makes every visitor download that file again on every page view. Keep it for the one script that really needs it, such as a script that embeds forms through iframes. It only acts in production: during your session the file already comes from your .sp domain, and it does not apply when the loader tag has data-stagepass-live-src="true". Details are in Skip the cache for one asset.

html
<script
  data-stagepass
  data-src="https://cdn.example.com/js/forms.js"
  data-stagepass-nocache
></script>

If you stay with stable file names, be careful with integrity. Every upload changes the file but not the tag, and browsers refuse a file that doesn't match its integrity. Either update the value on every upload, or leave integrity off for stable names.

Where the hashed files live is up to you: your own web hosting, a CDN, or a public GitHub repo. Where Do I Put My Files? compares the options. Stagepass doesn't host your files.

Frequently asked questions

How do I stop Webflow visitors from getting old JavaScript or CSS?

Load hashed files. stagepass build writes a copy of each file whose name contains a hash of its content, so every changed build gets a new URL that no cache has seen. Read the names from dist/manifest.json. See build and watch.

Does stagepass watch write hashed files?

No. Since CLI 2.4.0, stagepass watch and stagepass dev write only the stable dist/main.js and dist/styles.css and leave manifest.json alone. Hashes come only from stagepass build. See build and watch.

Where do I find the hashed file name and the integrity value?

In dist/manifest.json after stagepass build. Each entry has file, the hashed name, and integrity, a sha384 SRI value for the tag. See build and watch.

Does my Stagepass session still work with hashed production URLs?

Yes, as long as each tag has data-stagepass-path, for example dist/main.js. The session swaps in that stable local file and removes integrity from the swapped tag. See Attribute reference.

Can I turn off caching for a single script?

Yes. Add data-stagepass-nocache to that tag, with loader 2.5.0 or later. Every visitor then loads it with a fresh ?_cb= on every page view, so use it sparingly. See Skip the cache for one asset.