views:

858

answers:

3

Suppose I have a 400K text file which I want to read from a javascript. The problem is, my target audience have a slow connection, so 400k might take too long to load.

I suppose I need to compress the file, but well, how can I decompress it via javascript on the client side?

Is it worth it, or will the time needed for decompression negate the time saved in downloading?

UPDATE

Just to be clear, the file is text (data) not code.

A: 

could you use HTTP compression?

Bluephlame
If I knew I wouldn't ask
hasen j
You can be little more polite.
NLV
+4  A: 

You can GZip the text file, and sent it to the browser. That way you wont have to do anything on the client side, the browser itself will decompress it.

Kirtan
+1  A: 

This looks interesting: http://rumkin.com/tools/compression/compress_huff.php

A few tests with a LOT of text turned up a pretty good result.

Travis
I just tried it, it increased the size rather than decreasing it
hasen j
Yeah, on small amounts of text is does increase the size but when you put a few pages of random text in there it compresses it pretty well. I'm seeing 30-50% compression.
Travis