Preload and sources
Load screens ahead of time, list a screen's package IDs, and learn how sources, caching, timeouts and the offline copy work.
Loading fetches a screen without showing it and sends no analytics events. Use it to read what a screen needs before you show it, for example to list its package IDs and fetch prices, or on mobile to warm the cache so present opens at once.
loadPaywall resolves a source to its JSON and returns it. Draws nothing.
function loadPaywall(source: PaywallSource, init?: RequestInit): Promise<PaywallJson>;import { configure, loadPaywall, getPackageIds } from '@ui-kit/web';
configure({ apiKey: 'pk_...' });
const paywall = await loadPaywall({ placement: 'upgrade_button' });
const ids = getPackageIds(paywall); // ['monthly', 'annual']
const products = await fetchPricesFor(ids); // your own codeinit is extra options for fetch, used only for a URL source.
Mobile preload fetches the placements' screens, images and fonts. A placement that cannot be loaded is skipped silently: it never throws. On web there is no separate preload; the SDK keeps its own copy of each answer (below).
Sources
| Source | Loads | Analytics |
|---|---|---|
Placement (web { placement: 'key' }) | The screen the placement shows now. A schedule in force is applied by the server; for an A/B test the user's side is picked. Audiences, frequency limit and holdout are decided when you present, not on load. Recommended. Needs the API key. | Yes (when presented) |
Paywall ID ({ paywallId: 'id' }) | That screen's published version. Needs the API key. | Yes |
URL (web only) 'https://.../paywall.json' | JSON from any URL, such as a file you host yourself. Not cached by the SDK, no timeout of its own. A non-2xx answer fails with Could not load paywall (STATUS) from URL. | None |
| JSON | The JSON as it is. | None |
A JSON object or URL must have the screen format: default_locale, components_config.base and components_localizations. Web unwraps a wrapper object with a paywallData field, and a missing components_localizations becomes {}. Download a screen's JSON with Download JSON on the Screens page. A downloaded file is a copy and does not change when you publish; a placement does.
Caching and the offline copy
For a placement or paywall ID the SDK keeps a copy of the last answer:
- It sends the last
ETagit saw, so an unchanged screen costs a short304. - Web keeps the copy in memory and in
localStorageunderuikit:v1:plus the request URL, and skips the browser's HTTP cache. Mobile keeps it on disk in the app's cache, with fonts. Icons and catalog fonts a screen uses are named in its delivery, so the phone does not look them up elsewhere. Images are cached for the session (and on disk on iOS). - The Miniwall CDN caches an answer for about 30 seconds, so a publish reaches your site or app within about a minute.
- If the network fails, the request times out or the server answers 5xx, the last copy is used. A published screen keeps working offline.
- A 4xx answer (wrong key, unknown placement, a website or app that is not allowed) is an error, even if there is a copy.
The timeout is timeoutMs (default 8000 ms; iOS timeout, 8 seconds), set in configure. After it the saved copy is used. With no copy the call fails with UIKit: the paywall took too long to load (web) or Miniwall: the screen took too long to load (mobile).
The delivery response
For reference, the SDK calls GET {apiUrl}/v1/sdk/placements/KEY?key=pk_...&v=2 (or /v1/sdk/paywalls/ID). Mobile also sends X-Miniwall-SDK (for example ios/0.1.0) and X-Miniwall-App (for example ios:com.acme.app).
| Field | What it is |
|---|---|
placement, paywallId, version | Which placement, screen and published version. |
paywall | The screen JSON. |
packages | The package IDs you must price. |
experiment | A running A/B test: id, shareB and side B's full delivery. null when none. |
rules | The audiences in order: id, conditions and the screen to show, or null for nothing. |
frequency | The frequency limit, or null. |
holdout | The holdout id and share, or null. |
display, trigger | The placement's format and trigger. |
Audiences, frequency limit and holdout ship as rules and are decided on the device, so attributes never leave it. See Targeting attributes.
Related
- Present a screen
- Purchases and prices (
getPackageIds) - Errors
- Events and privacy