Search code examples
javascriptcompressiontext-files

javascript text compression/decompression


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.


Solution

  • 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.