keyv icon indicating copy to clipboard operation
keyv copied to clipboard

Browser support

Open dremekie opened this issue 3 years ago • 12 comments

As mentioned in #64 , browser support would be useful . We're looking to run this in environments which are based on a web platform api (e.g. Cloudflare Workers).

Is there interest in addressing the two points of change mentioned in #64 ?

  • Use https://www.npmjs.com/package/eventemitter3 instead of Node's built-in Event Emitter
  • Use https://www.npmjs.com/package/buffer over using json-buffer which relies on Node'sBuffer

dremekie avatar Feb 24 '22 22:02 dremekie

@dremekie - thanks so much and I am adding this to a feature that we are going to look at in the next 90 days to implement. Do you have a use case that we can validate this against other than Cloudflare Workers? Would this help with other cloud providers serverless implementations?

jaredwray avatar Mar 21 '22 21:03 jaredwray

I was just looking to see if there was a localStorage adapter and stumbled upon this ):

alfaproject avatar Apr 28 '22 10:04 alfaproject

I was just looking to see if there was a localStorage adapter and stumbled upon this ):

@alfaproject - make sure to upvote with a 👍 as we are evaluating if this makes senses.

jaredwray avatar Apr 28 '22 15:04 jaredwray

I upvoted, thanks!

Client storage is getting increasingly more popular I think: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Client-side_storage

We are trying to do more and more computation at the edge and preferably at the customers browser so we offset resources to the client or as close to the client as possible and I think that's getting more popular, especially with the whole serverless thing (;

alfaproject avatar Apr 28 '22 16:04 alfaproject

I upvoted, thanks!

Client storage is getting increasingly more popular I think: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Client-side_storage

We are trying to do more and more computation at the edge and preferably at the customers browser so we offset resources to the client or as close to the client as possible and I think that's getting more popular, especially with the whole serverless thing (;

Interesting. Why would you want to use Keyv instead of just talking directly to these storage providers?

jaredwray avatar Apr 28 '22 16:04 jaredwray

Because depending on the environment I might want to load a different provider. For example, in incognito I would use memory adapter because localStorage is not available. If I need to save more than 5mb of data, I would switch to IndexedDB without changing any of my cache code. Likewise, if I want to update our Cloudflare workers, I can either use their KV cache or their durable objects stuff, etc

Also, in the back-end we already use Keyv, so having a unified cache interface across the stack improves DX

alfaproject avatar Apr 28 '22 17:04 alfaproject

@jaredwray I'm looking to use this in serverless environments which have no NodeJS support. I think this library would be extremely beneficial within those environments as it provides a clean/well-tested layer of abstraction. Do you think this will make the "enhancement list"?

dremekie avatar May 18 '22 17:05 dremekie

@dremekie - we are looking at how hard this would be and what compatibility issues we would see by doing this. Should have an update in the next week or so.

jaredwray avatar May 18 '22 18:05 jaredwray

@dremekie - we are now looking at an implementation for this.

jaredwray avatar May 28 '22 00:05 jaredwray

@jaredwray Thanks... that's great news

dremekie avatar May 28 '22 23:05 dremekie

@dremekie @alfaproject - wanted to get an update to you. We found out that we need to do an architecture change on the caching layer before we make this work on the browser. Tracking it here: https://github.com/jaredwray/keyv/issues/407

jaredwray avatar Jul 19 '22 15:07 jaredwray

Thanks for the update @jaredwray (:

alfaproject avatar Jul 19 '22 15:07 alfaproject

To better support browser then i would wish for

  • ESM
  • use EventTarget instead of EventEmitter
  • use Uint8Array instead of Buffer
  • use Web standard CompressionStream / DecompressionStream instead for compression

jimmywarting avatar Dec 13 '22 13:12 jimmywarting

Any updates on when browser support will be released?

radman-x avatar Feb 24 '23 18:02 radman-x

@radman-x - this is still in planning for this year and we are first working on converting the project over to typescript. Once that is done then we will be building out the browser compatible version if possible. There is still some investigation on this.

Also, we are looking at ESM but the focus is to make it as compatible as possible first.

jaredwray avatar Feb 24 '23 19:02 jaredwray

Hi All. This is now in flight and I am going to close this and you can comment on this issue moving forward: https://github.com/jaredwray/keyv/issues/868

jaredwray avatar Jul 12 '23 20:07 jaredwray