Skip to main content

Initialization

To initialize the Recharge JavaScript SDK you will need to do it within the root of your theme (wherever the <head /> element is located). Generally this is located in a file called theme.liquid.

Example

Load the JavaScript SDK script and initialize it with your storefront token and store domain.

  • storefrontAccessToken - this token can be created via the merchant-admin where you manage your API tokens

theme.liquid

<html>
<head>
...
<script src="https://static.rechargecdn.com/assets/storefront/recharge-client-1.18.0.min.js"></script>
<script>
recharge.init({
// optional when in a shopify environment
storeIdentifier: '{{shop.permanent_domain}}',
// required for API access
storefrontAccessToken: 'storefrontAccessToken',
// retry middleware function if/when Recharge session expires
loginRetryFn: () => {
return recharge.auth.loginShopifyAppProxy().then(session => {
...
// store recharge session
...
return session;
});
},
});
</script>
</head>
...
</html>