prefetchFlow()
Prefetch a flow's content for faster display. Silent if fails.
This is optional. Prefetching simply pre-loads flow content in advance, improving startup speed when the flow is triggered. Flows work perfectly fine without prefetching—they'll just fetch content on demand when startFlow() is called.
Method Signature#
Mobana.prefetchFlow(slug: string): Promise<void>Usage#
App.tsx
// Prefetch during app startup
Mobana.prefetchFlow('onboarding');
// Later, when ready to show (instant if prefetched)
const result = await Mobana.startFlow('onboarding');prefetchFlow() silently fetches and caches the flow content. If it fails (network error, flow not found, etc.), it fails silently without throwing.
Parameters#
| Parameter | Type | Description |
|---|---|---|
slugRequired | string | The flow's unique identifier (slug) from the Dashboard. |
Prefetching Multiple Flows#
App.tsx
// Prefetch multiple flows during app startup
await Mobana.init({ appId: 'a1b2c3d4' });
// Prefetch flows you know the user might see
Mobana.prefetchFlow('onboarding');
Mobana.prefetchFlow('push-permission');
Mobana.prefetchFlow('premium-upsell');Prefetching is non-blocking, so you can call it multiple times without waiting.
Conditional Prefetching#
Prefetch flows based on user state or attribution:
// Prefetch based on user state
const attribution = await Mobana.getAttribution();
if (attribution?.utm_campaign === 'premium_promo') {
// User came from a premium campaign, prefetch upsell
Mobana.prefetchFlow('premium-upsell');
}
if (!user.hasSeenOnboarding) {
Mobana.prefetchFlow('onboarding');
}How It Works#
- Fetches content: Downloads the flow's HTML, CSS, and JavaScript.
- Caches locally: Stores content in AsyncStorage for offline access.
- Version-aware: If the flow is updated in the Dashboard, the SDK will fetch the new version.
- Instant display: When you call startFlow(), the cached content is used immediately.
Best Practices#
- Prefetch early: Call during app startup or splash screen for best UX.
- Don't over-prefetch: Only prefetch flows the user is likely to see.
- Conditional prefetch: Use attribution or user state to decide which flows to prefetch.