Appearance
Theming, Caching & DOM Injection
1. In-memory caching
Content rarely changes minute-to-minute, so the SDK caches every namespace and blob in memory: the first getConfig('theme') hits the network; subsequent calls return instantly from memory.
Invalidation contract: caching never serves stale content forever; CONTENT_UPDATED events notify connected clients to refresh, and a 5-minute TTL floor catches clients that were not connected. To force a refresh at any time:
javascript
sdk.content.clearCache();text
GIVEN a cached namespace or blob
WHEN a CONTENT_UPDATED event for it arrives, OR its 5-minute TTL elapses,
OR clearCache() is called
THEN the next fetch goes to the network and the cache holds fresh data.2. Instant DOM theming
A common use for the theme namespace is brand styling. The applyThemeToDom() helper converts a config object's string and number values into CSS variables on the document root; camelCase keys become kebab-case variable names:
javascript
const theme = await sdk.content.getConfig('theme');
// e.g. { primaryColor: '#ff0000', borderRadius: 8, darkMode: false }
sdk.content.applyThemeToDom(theme);
// --primary-color: #ff0000; --border-radius: 8;Booleans are ignored by design; CSS variables are strings, and "false" is not a useful one. Model binary states with string values instead (e.g., themeMode: 'dark' | 'light') and branch in your CSS/classes.
Using the CSS variables
css
.btn-primary {
background-color: var(--primary-color, #cccccc);
border-radius: var(--border-radius, 4px);
}