The SDK allows you to fetch and cache (“preload”) multiple resources from the Smile API in a single call, offering improved performance as compared to making multiple individualDocumentation Index
Fetch the complete documentation index at: https://dev.smile.io/llms.txt
Use this file to discover all available pages before exploring further.
get() calls. Preloaded data is stored in an internal cache and can be accessed through preloaded() methods on each resource.
Resources that can be preloaded
Preloading is possible for a variety of resources using the corresponding resource key. Some resources are customer-specific and require a customer to be logged-in before they can be preloaded, while other resources are not and can be preloaded regardless of whether there is a currently logged-in customer.| Resource | Resource key | Requires a logged-in customer |
|---|---|---|
| Customer Points Products | customerPointsProducts | Yes |
| Customer Points Wallet | customerPointsWallet | Yes |
| Customer VIP Status | customerVipStatus | Yes |
| Earning Rules | earningRules | No |
| Points Products | pointsProducts | No |
| Points Settings | pointsSettings | No |
| Reward Fulfillments | rewardFulfillments | Yes |
| VIP Tiers | vipTiers | No |
How to preload resources
Resources can be preloaded at multiple points in the SDK lifecycle, using any of the supported preloading methods:- During initialization - By passing a
preloadparameter toSmile.initialize() - During customer login - By passing a
preloadparameter toSmile.customer.login() - Any other time - By calling
Smile.preload()
preloaded() method on the resource class.
Understanding the cache
The internal cache is updated any time a resource is preloaded using any of the supported preloading methods. Whenever you preload a resource, the SDK will:- Fetch the latest entries for the specified resource from the API.
- Remove any existing entries from the cache for the specified resource.
- Add the newly retrieved entries from the API to the cache.
Refreshing cached data
To refresh cached data for a given resource, callSmile.preload() (or any other of the supported preloading methods) again with the same resource key.
Cached data persistence
Preloaded data persists in the cache until either:Smile.reset()is called or a hard page reload occurs — at which point all preloaded resources are removed from the cache.Smile.customer.logout()is called — at which point only customer-specific preloaded resources are removed from the cache.
Sample code
JavaScript