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

compressing in webworker and passing a transferable arraybuffer to save in LocalStorage #18

Closed
urbien opened this issue Nov 24, 2013 · 1 comment

Comments

@urbien
Copy link

urbien commented Nov 24, 2013

I have a use case that I believe is quite common in JS frameworks.

We are using LocalStorage for caching app assets (js, css, html templates, etc.). To offload the main thread we use web workers, that xhr the app assets from the server. Ideally we would compress and save to LocalStorage in a web worker, but they do not have access to LS.

So, we need to compress in web worker, pass the result via postMessage to the main and then save arraybuffer to LocalStorage. To avoid expensive copy, postMessage allows to pass the result as a 'transferable' arraybuffer.

So it seems converting a compressed arraybuffer to utf16 needs to be done in a separate pass on the main thread.

@pieroxy
Copy link
Owner

pieroxy commented Nov 25, 2013

I haven't tackled these issues yet due to the poor support in IE. IE10 still being the odd IE in terms of usage, it doesn't make sense for me yet to add typed array support by fear of breaking things on IE8-.

In all my apps I communicate to my workers with a straight String and while not perfect, it works fine for me.

Releasing an implementation that outputs a typed array instead of a string is trivial. Just update the writeBit and (and readBit for the decompressor) in LZString 1.0.3. With an Uint16Array it should really be trivial.

@pieroxy pieroxy closed this as completed Nov 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants