Skip to content

Commit

Permalink
🎨 Optimized loading stripe scripts only when it is needed (#11499)
Browse files Browse the repository at this point in the history
closes #11463

- Ghost used to always load stripe.js into the frontend of all pages when memberships are enabled, even when Stripe isn't configured / memberships to a page are free. This changes Ghost's behaviour to only load stripe.js when both stripe API tokens are present & not empty (the quickest way to verify that Stripe is fully configured & operational on a blog).
- Needs a follow-up cleanup removing confusing/not functional `isPaymentConfigured` method from members service
  • Loading branch information
Sven Ewers authored and naz committed Jan 17, 2020
1 parent 8624587 commit 0030acf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions core/frontend/helpers/ghost_head.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ function finaliseStructuredData(metaData) {
}

function getMembersHelper() {
return `
<script src="https://js.stripe.com/v3/"></script>
<script defer src="${getAssetUrl('public/members.js')}"></script>
`;
const stripePaymentProcessor = settingsCache.get('members_subscription_settings').paymentProcessors.find(
paymentProcessor => paymentProcessor.adapter === 'stripe'
);
const stripeSecretToken = stripePaymentProcessor.config.secret_token;
const stripePublicToken = stripePaymentProcessor.config.public_token;

var membersHelper = `<script defer src="${getAssetUrl('public/members.js')}"></script>`;
if (!!stripeSecretToken && stripeSecretToken !== '' && !!stripePublicToken && stripePublicToken !== '') {
membersHelper += '<script src="https://js.stripe.com/v3/"></script>';
}
return membersHelper;
}

/**
Expand Down

0 comments on commit 0030acf

Please sign in to comment.