https://www.growthbook.io/ logo
m

millions-diamond-13295

07/05/2022, 5:32 PM
Hi! I wanted to add Growthbook via unpkg script in a SPA (Nextjs). I know I can just npm install the package but this is the requirement I currently need to work with. Trying to understand what best practice here would be 1. User navigates to a page with growthbook. Growthbook gets loaded client-side. 2. User then navigates to a page without growthbook. Since its a SPA, Growthbook variables will still be in memory. The more general question is: are there any good ways to cleanly load and unload client-side scripts for single page apps?
f

future-teacher-7046

07/05/2022, 7:49 PM
Are you able to hook into the React code at all or does it need to just be a
<script>
tag in the html template?
m

millions-diamond-13295

07/05/2022, 7:59 PM
Needs to be a
<script>
tag unfortunately Is this possible?
f

future-teacher-7046

07/05/2022, 8:03 PM
It should be possible to load the SDK like that. How are you planning to use it in your app though? Do you want to do something like
growthbook.evalFeature(...)
inside a React component and have it use the globally loaded instance from the script tag?
m

millions-diamond-13295

07/05/2022, 9:36 PM
Ah @future-teacher-7046 we just pushed back and were able to go with react implementation. Thanks for the time
4 Views