TenanciTenanci

Help centerProjects, domains & DNS

Performance and caching

How Tenanci keeps your customers' domains fast and light: edge file caching, static files straight from the origin, a short HTML cache and compression.

Going through Tenanci doesn't slow your app down: the edge keeps heavy files already compressed, sends the browser straight to the origin for files that need no changes and, if you want, answers with the HTML instantly even when the app server is slow. Almost everything is automatic; what you can tune lives in the Performance card on each domain's Settings tab.

What's on by default

Without any setup:

  • Edge file cache: JS and CSS files the origin says to keep for at least a day (the versioned bundles every build produces) are stored on the edge with the customer's domain already swapped in and compressed at the highest level (brotli, zstd or gzip, depending on the browser). Later visits get them straight from the edge, without touching the origin;
  • Compression: every other response (HTML, JSON, text) is compressed on the fly with zstd or gzip;
  • Static files straight from the origin: see the next section. It's on for every new domain.

The edge follows what the origin says: it only stores 200 responses without cookies and without private/no-store. A file that changes on every deploy under the same name (no version in the name and no long cache) keeps coming from the origin on every visit.

Static files straight from the origin

With Static files straight from the origin on, the visitor's browser downloads files that never change and need no adjustment directly from the app server:

  • immutable JS and CSS that don't mention the origin's domain and that the origin allows other sites to load (CORS);
  • immutable fonts and images, through a short redirect to the origin.

The result is less traffic through the edge and faster pages. The first request for each file goes through the edge (that's when we find out whether it's safe to send it direct); the following ones go straight to the origin.

To change it:

  1. Open the project, go to Domains and click the domain;
  2. Open the Settings tab;
  3. In the Performance card, turn Static files straight from the origin on or off. The change is published right away.

HTML cache

The HTML cache makes the edge keep the page returned by the origin and answer with it instantly for a short time: 1 minute, 5 minutes or 1 hour (default: Off). Once that time is up, the edge still serves the stored version and fetches the new one in the background; only the first visitor after a long quiet period waits for the origin.

What gets stored is the origin's HTML, before Tenanci's adjustments. SEO, TailorKit, marketing tags, analytics and the domain swap are still applied on every visit, always with the current settings.

For safety, the edge only stores a page when:

  • the response is 200 and doesn't set an app cookie (Set-Cookie);
  • the origin hasn't marked the page private or no-store;
  • the request comes from a browser opening the page, without Authorization.

Campaign parameters (utm_*, gclid, fbclid and the like) don't count for the cache: ad traffic reuses the same stored page, and the parameters still reach the origin and analytics.

To turn it on:

  1. Open the domain and go to the Settings tab;
  2. In the Performance card, pick a duration under HTML cache;
  3. That's it: the change is published within seconds.

Via the API

Both options are domain fields in PATCH /domains/:id: assetsDirect (true or false) and htmlCacheSeconds (0, 60, 300 or 3600). The current values are under assets in GET /domains/:id.

curl -X PATCH https://api.tenanci.com/v2/domains/dom_4h7n1q \
  -H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"htmlCacheSeconds":300,"assetsDirect":true}'

Measuring the result

The performance reports in analytics show each domain's Web Vitals, including TTFB (time to first byte), which is where the HTML cache shows the most. Pages served from the HTML cache carry an X-Cache: HIT header you can see in the browser's developer tools.