Hey guys, we are sending 1 million requests per da...
# ask-questions
t
Hey guys, we are sending 1 million requests per day despite only having 5k DAU and our feature flags never change. How can we reduce the number of requests to something more reasonable like 100k per day? This unexpectedly costed us $400+ bill last month
Copy code
const growthbook = new GrowthBook({
    apiHost: "<https://cdn.growthbook.io>",
    clientKey,
  });
we are just using the default settings is adding the following enough, or should we also disable backgroundSync entirely?
Copy code
configureCache({
    staleTTL: 1000 * 60 * 60, // expire after 1 hour
  });
cc @fresh-football-47124 any guidance would be super helpful here
hmm it seems like even with the staleTTL, I am getting an SSE event every 30 seconds even though nothing on the server side has changed
is this the only way to fix it?
s
Hi! Two things: •
loadFeatures
is deprecated. You should use
init
instead. • With
init
, you can then set
streaming: false
. Those SSEs are because of streaming, which is for realtime feature updates. Setting this to false will greatly reduce your CDN calls. Additionally, you can then also implement more aggressive caching with this: https://docs.growthbook.io/lib/js#caching
t
thank you @strong-mouse-55694! What's diff between
Copy code
const growthbook = new GrowthBook({
    apiHost: "<https://cdn.growthbook.io>",
    clientKey,
    backgroundSync: false, 
  });
and
Copy code
growthbook.init({streaming:false})
? Also do we need to keep
Copy code
setInterval(
    () => {
      growthbook.refreshFeatures();
    },
    1000 * 60 * 15
  );
if we want to make sure the feature flag are not too stale right? Or can we remove this and rely on cache being stale?
s
The first code instantiated the GrowthBook class and the second runs the init method, which is where features are fetched. For the feature caching, see the doc I linked. It shows the default caching values and provides an object for configuring if needed. I wouldn't do it with setInterval. Also, what kind of app is this?
t
Thanks for the clarification! it's a chrome extension.
The first code instantiated the GrowthBook class and the second runs the init method,
I meant there's
backgroundSync: false,
option in the first code. what's the diff between that option and
streaming:false
?
s
backgroundsync
is deprecated.