CDN for SPAs

Give the HTML entry point a short cache lifetime and keep hashed bundles available across releases. Verify client-side navigation and direct links to nested routes.

Example release policy
Versioned resource
/assets/app.51ea.js
Refresh on publication
/index.html

Coordinate the application shell and its bundles

Cache hashed bundles with long TTLs. Serve index.html from Cloud CDN with purge on deploy. Keep APIs and auth on the origin.

Boot from a nearby PoP

The browser can fetch versioned JavaScript, CSS and fonts without another request to the application origin on a cache hit.

Deploy = purge the shell

index.html picks up new hashed filenames as soon as CI purges it.

APIs remain the app origin

Auth and JSON stay dynamic. The CDN is for the shell and public assets.

Configuration

Cloud CDN overview
  1. Host the production SPA build

    Any HTTPS origin that serves the bundled files.

  2. Long-cache hashed assets

    Fingerprinted files rarely need purge.

  3. Purge index.html on release

    Add purge to the SPA deploy pipeline.

  4. Fallback unknown paths to the shell

    Configure origin or hosting rules so client routes serve index.html.

Operational outcomes

  • SPA bundles are global
  • HTML shells update on deploy
  • APIs stay on the origin
  • Client-side routes still boot from cache

Frequently asked questions

Does this work with React, Vue and Angular?

Yes. See the dedicated framework pages for bundler-specific notes.

How should I treat environment config?

Prefer build-time config in hashed files. Runtime config JSON can be cached with a short TTL.

Can I prerender marketing routes?

Yes. Cache prerendered HTML like any static page and purge on deploy.

What about service workers?

Cache the worker file carefully. Purge or version it when the worker must update immediately.