2

I have a string, it is about 200 000 characters long. There is a lot of repetition in this string. I was wondering if there was a way that I could compress this string server side (c#) and the once I receive it client side (JS) that I decompress this string.

An example of the data: enter image description here

2

2 Answers 2

2

I don't know how well Javascript itself (through libraries) can use compressed data, but it doesn't need to.

When you GZip the data server side and set the "Content-Encoding" header value to "gzip", then the browser will decompress it before handing it over to your js code. So you have the benefit of small transport size and fast decompression.

Check beforehand whether the browser can do it, by checking the request header value "Accept-Encoding". If that contains "gzip" (which is usual), then the browser will decode it.

Further reading (specific for WebApi): http://blog.developers.ba/asp-net-web-api-gzip-compression-actionfilter/ and http://benfoster.io/blog/aspnet-web-api-compression

Sign up to request clarification or add additional context in comments.

Comments

1

Yes, you can pick any compression algorithm you want, implement that algorithm in C# to compress, and then again in javascript to decompress. Changing between C# and JavaScript does not cause you any difficulties, except the fact that you need to implement it in both languages of course.

I recommend you search for LZ compression algorithms.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.