CDN for Gatsby

Distribute Gatsby builds from a static origin. Publish the new asset set before updating cached HTML and page-data files that refer to it.

Example release policy
Versioned resource
/component---guide-d049.js
Refresh on publication
/page-data/guide/page-data.json

Coordinate HTML and page-data updates

Pull the Gatsby public/ output through Cloud CDN. Cache hashed assets for a long time, purge HTML on each build, and optionally transform images at the edge.

Distribute the public build directory

HTML and page-data files identify the bundles a page needs. Publish them together so visitors receive a consistent build.

Slice images without origin work

Cache Gatsby image output or replace some derivatives with edge transforms.

Build-time purge

Each Gatsby build can purge HTML so new pages go live immediately.

Configuration

Cloud CDN overview
  1. Host the Gatsby public directory

    Use any HTTPS origin Cloud CDN can pull — a files host or a static host.

  2. Cache hashed files longer

    Page-data and HTML get purgeable TTLs. Fingerprinted JS/CSS can live longer.

  3. Purge on CI

    After gatsby build, purge HTML and page-data paths.

  4. Attach the domain

    Map TLS and DNS once a test hostname is correct.

Operational outcomes

  • Gatsby sites are delivered globally
  • CI can purge on every build
  • Images are cached at the edge
  • The origin is only needed on misses

Frequently asked questions

Does this work with Gatsby Image?

Yes. Cache the generated files. You can also serve some sizes via Cloud CDN image optimization.

Can I use DSG or SSR routes?

Cache static routes. DSG/SSR paths should only be cached when the HTML is shareable.

What origin works best?

Any HTTPS origin that serves the Gatsby build. Cloud CDN does not require a specific static host.

How do client-only routes behave?

The shell HTML can be cached. Authenticated API calls from those routes stay dynamic.