views:

291

answers:

1

I've got some strings that I need to compress server-side in C#, then decompress client-side in JavaScript. What can I use to accomplish this?

+6  A: 

Assuming you're fetching this data over HTTP, is there any reason you can't do this at the HTTP level? (See this article for information about HTTP compression.)

That way you shouldn't need to do anything on the client side, apart from making sure that the request includes the appropriate Accept-Encoding header. Depending on your server, you may be able to just tweak some server settings to get the compression automatically on that side too...

To be honest, it's worth breaking out WireShark to check exactly what's going up and down the wire already. It's just possible you've already got compression without knowing it :)

Jon Skeet
Just check the headers with something like Firebug. The server response is cleary marked as gzipped if it is, and it has no Content-Lenght because of that (on the fly compression). Firebug will show you the actual bytes transferred.
Vlagged
Could also use Fiddler [http://www.fiddler2.com] instead of WireShark.Imho, it is easier to use, if you need HTTP-level data only and can make your connection go through a proxy.
VladV