Skip to content

ETag (API Reference)

app.setConfig({ etag: true });
app.setConfig({ etag: { weak: true, exclude: ['/stream/*'] } });

Configures ETag generation globally. When activated, responses include an ETag header representing the body contents, and the server automatically processes If-None-Match headers to return 304 Not Modified.

ParameterTypeDescription
etagboolean | EtagOptionstrue = strong ETags. Object = full options. false = disable.

app.useEtag(options?)

Alternative to setConfig, enables ETags and returns the app instance for chaining.

ParameterTypeDefaultDescription
options.weakbooleanfalseIf true, generates weak ETags (W/"...")
options.excludestring[][]Paths that should not receive ETags

KaelumApp — the app instance for chaining.


interface EtagOptions {
weak?: boolean;
exclude?: string[];
}

  • Dependencies: Uses Express’s native ETag engine and Node’s native crypto.createHash('sha1'). No external packages required.
  • Weak vs Strong: Strong ETags indicate byte-for-byte equivalence. Weak ETags (prefixed with W/) indicate semantic equivalence.
  • Excluded Paths: Paths matching strings or wildcards (/*) in the exclude array will have their ETag header stripped before the response is finalized. Useful for streams or Server-Sent Events.

// Strong ETags (default)
app.setConfig({ etag: true });
// Weak ETags
app.useEtag({ weak: true });
// Exclude specific paths
app.setConfig({
etag: {
exclude: [
'/sse', // Exact match
'/webhooks/*', // Wildcard match
],
},
});