Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service worker compatibility #201

Open
jeremiewtd opened this issue Apr 25, 2024 · 0 comments · May be fixed by #202
Open

Service worker compatibility #201

jeremiewtd opened this issue Apr 25, 2024 · 0 comments · May be fixed by #202
Assignees
Labels
enhancement New feature or request

Comments

@jeremiewtd
Copy link

Describe the feature request

We would like to use unleash-proxy-client-js in a service worker context, more precisely in the context of a browser extension service worker (and "non persistent background").

Background

We are facing some issues while running unleash-proxy-client-js in a service worker context (browser extension service worker).

First issue : each time the proxy is instantiated, it fetches the flags, no matter how old they are in the storage. In the context of a service worker which stops and restarts multiple times depending on its use this will cause a huge overhead on our proxy server (we have hundreds of thousands of live extensions).

Second issue : the internal use of setTimeout and setInterval which is not compatible with the lifecycle of this kind of service workers which have to use "browser alarms" instead, see documentation.

Solution suggestions

For the first issue (fetch call on load) the solution could be to check "flag expiration" on load, if flags are younger than the "refreshInterval", it should not fetch (we have to store a new "last update" timestamp) OR use the bootstrap value on first load and don't fetch (wait for next refresh).

For the second issue (usage of setInterval), we could expose as public methods the "refresh" toggles and metrics so that library consumers can call them themself if needed (we could so add our own "alarm" to refresh the toggles and metrics).

@jeremiewtd jeremiewtd added the enhancement New feature or request label Apr 25, 2024
@ivarconr ivarconr self-assigned this May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

2 participants