Skip to content

Configuration

spf.config holds the global configuration, initialized from SPF's defaults (original docs) with modern additions. Pass a partial config object to spf.init() (or spf.config.init()), or read and write individual keys at runtime.

Keys

KeyDefaultMeaning
url-identifier?spf=__type__URL marker for SPF requests; __type__ is replaced by navigate | prefetch | load.
link-classspf-linkClass marking an <a>/<form> as SPF-enabled.
nolink-classspf-nolinkClass opting an element out of SPF handling.
cache-lifetime600000 (10 min)Maximum time (ms) a cache entry is valid.
cache-max50Maximum number of cache entries (LRU).
cache-unifiedfalseWhen true, cached responses are eligible for all navigations.
request-timeout0Request timeout in ms; 0 = none.
request-headersnullGlobal request headers object.
reload-identifiernullReason parameter appended to fallback reload URLs.
navigate-limit20Max navigations per session (SPF behavior).
navigate-lifetime86400000 (24 h)Session lifetime in ms for the navigation limit.
animation-classspf-animateClass added to animated elements during view transitions.
animation-duration425View transition duration in ms (informational).
advanced-header-identifiernullWhen set, identifies SPF requests via X-SPF-Request instead of the URL.
experimental-prefetch-mousedownfalsePrefetch on mousedown (SPF experiment).
prefetch-viewporttruePrefetch spf-links as they enter the viewport.
speculationprefetchSpeculation rules strategy: prefetch | prerender | none.

API

MethodSignatureEffect
init(optConfig?: Partial<SpfConfig>) → voidApply an optional config over the defaults.
get(key) → valueRead a configuration value.
set(key, value) → valueSet a configuration value; returns it.
clear() → voidReset to defaults.

Examples

js
spf.init({
  'url-identifier': '?spf=__type__',
  'cache-unified': true,
  speculation: 'prerender',
});

spf.config.set('prefetch-viewport', false);
const cls = spf.config.get('link-class'); // "spf-link"