Caching and webhooks
Keep the API fast with shared caching, and notify other systems when content changes.
Caching strategy
Zero build on publish does not mean zero caching. Put a short cache between visitors and HydroGo and let freshness be a number you choose.
| Layer | Setting | Effect |
|---|---|---|
| Your frontend response | cache-control: public, max-age=0, s-maxage=30, stale-while-revalidate=60 | A CDN serves a response for 30 s, then refreshes in the background. Edits appear within about half a minute. |
| Sitemap | s-maxage=300 | Crawlers rarely need fresher data. |
| Media | Long cache lifetime at your CDN | Media objects are immutable: a replaced file gets a new id, so old URLs stay valid. |
| Previews and admin | private, no-store | Never cache. |
// SvelteKit load function
export async function load({ setHeaders }) {
const news = await hydro.listNews('en', 10);
setHeaders({ 'cache-control': 'public, max-age=0, s-maxage=30, stale-while-revalidate=60' });
return { news };
}Webhooks
HydroGo can POST signed JSON events to your systems when content changes, for example to purge a CDN, trigger a static rebuild or notify a chat room. Internally, transactional outbox events (such as content.updated and site.updated) are mapped to the external webhook topics below (such as page.* and news.*).
webhooks:
- id: frontend
url: https://ci.example.com/hooks/hydrogo
topics: [page.published, news.published, news.retracted]# the secret never lives in YAML; it is read from the environment
HYDRO_WEBHOOK_SECRET=change-me
# shortcut for a single endpoint without any YAML
HYDRO_WEBHOOK_URL=https://ci.example.com/hooks/hydrogo
HYDRO_WEBHOOK_TOPICS=page.published,news.published,news.retracted| Topic | Fires when |
|---|---|
page.created, page.updated, page.published | A page changes or is published. |
news.created, news.updated, news.scheduled, news.published, news.retracted | The news lifecycle. |
user.invited | A staff invitation is created (contains personal data and is only sent to endpoints with allow_pii: true). |
order.created, tenant.provisioned | Commerce and tenancy events. |
List the exact catalog your binary supports with hydro events catalog.
Event payload
{
"id": "evt_01",
"topic": "news.published",
"aggregate_id": "art_42",
"payload_version": 1,
"data": { }
}Verify the signature
Each request carries X-Hydro-Event, X-Hydro-Timestamp, X-Hydro-Signature and an Idempotency-Key (the event id). The signature is sha256= followed by the hex HMAC-SHA256 of <timestamp>.<raw body> using your secret. Reject requests with an old timestamp and de-duplicate by Idempotency-Key; deliveries are retried on failure.
import { createHmac, timingSafeEqual } from 'node:crypto';
export function verify(rawBody: string, headers: Headers, secret: string): boolean {
const ts = headers.get('x-hydro-timestamp') ?? '';
const sig = headers.get('x-hydro-signature') ?? '';
if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;
const expected = 'sha256=' + createHmac('sha256', secret).update(`${ts}.${rawBody}`).digest('hex');
const a = Buffer.from(sig);
const b = Buffer.from(expected);
return a.length === b.length && timingSafeEqual(a, b);
}Static frontends
If you deliberately use a static site generator, point a webhook at your CI provider's build trigger and subscribe to page.published, news.published and news.retracted. This is an option for your frontend, not a requirement of HydroGo: server rendering with a short cache avoids rebuilds entirely.
http or https URLs without embedded credentials, and redirects are validated again. Use HTTPS and always verify the signature.