Skip to content
brought to you byVoidZero

Static Assets Caching ​

When someone returns to your app after a deploy, their browser can reuse the scripts and styles that haven’t changed. Vite gives a changed file a new name so the browser knows to fetch it.

Hashed assets ​

For example, Vite might write assets/app-Ab3xK9.js. The hash in the filename identifies its contents. Files in build.assetsDir (default assets/) get this header so browsers and the edge can keep them for a year.

Cache-Control: public, max-age=31536000, immutable

To change the directory for hashed assets, set build.assetsDir:

ts
// vite.config.ts
export default defineConfig({
  build: {
    assetsDir: 'static', // hashed assets go to dist/client/static/
  },
});

Setting build.assetsDir to "" disables directory-based immutable caching.

Supported meta-frameworks use their own asset directories automatically.

Native Cloudflare deployments ​

For apps that use Void routing, void deploy --platform cloudflare gives generated JavaScript bundles with content fingerprints immutable caching. Framework integrations use their asset configuration and _headers file. Files copied from public/ and custom build outputs with stable filenames keep normal revalidation, even when they live in the assets directory. CSS and other assets keep Cloudflare's default or your configured Cache-Control.

Use Custom Headers to choose a cache policy for other files. Apply immutable caching only to URLs that change whenever their content changes.

Non-hashed assets ​

Other static files, such as index.html and favicon.ico, are cached at the edge until the next deploy.

Cache-Control: public, s-maxage=31536000, max-age=0, must-revalidate

Browsers revalidate these files on each request.

Static asset caching applies to complete 200 responses to GET requests:

  • All paths in SPAs and static sites
  • Paths with file extensions such as .ico, .png, or .css in SSR projects

Requests to /api/* and requests with Cookie, Authorization, or Cf-Access-Jwt-Assertion bypass the static asset cache. Use Revalidation to cache public SSR pages.

Opting out ​

If your worker serves dynamic content at a URL that looks static (e.g., a dynamically generated image at /avatar.jpg), you can prevent caching by setting Cache-Control: private or Cache-Control: no-store in your response headers. Any response with Cache-Control containing private, no-store, or no-cache, or with a Set-Cookie header, bypasses the edge cache.

ETags and 304 Not Modified ​

Browsers can revalidate a file using its ETag. An unchanged file returns 304 Not Modified.

Custom headers ​

You can override caching headers or add your own for any static asset path using Custom Headers.

Void serves static files directly unless application code needs to handle the request first. API requests reach your Worker. Apps with middleware, routes outside /api, Pages, or SSR run application code before serving fallback HTML.

SPAs serve index.html for unmatched HTML navigation so client-side routing works. For a static site with a 404.html page, set routing.notFound:

ts
import { defineConfig } from 'void/config';

export default defineConfig({
  routing: { notFound: '404-page' },
});

Choose single-page-application, 404-page, or none. These settings preserve which requests reach middleware and API handlers. Intentional API 404 responses keep their status and body.

SvelteKit, Nuxt, Analog, and Astro handle their own error pages and ignore routing.notFound. For direct Cloudflare deployment with TanStack Start, React Router, or vinext, configure the asset binding, directory, and routing policy through the framework's Cloudflare config.

On direct Cloudflare deployments, SvelteKit, Nuxt, Analog, and Astro serve built files and prerendered pages without running the Worker. Other requests reach the framework.

To run server code before serving an asset, set run_worker_first under cloudflare.assets in void.config.ts. Setting it to true runs the Worker on every request and counts toward Worker request usage.