Is it possible to compress data between server and client through js?

Discussion in 'JavaScript' started by wormy, Aug 29, 2006.

  1. #1
    Most of the text(code) data that flies back and forth is uncompressed. Many times .bmp files and other files might be uncompressed as well. Is it feasable to add compression-decompression algorithms to speed things up? The compression would occur on the server side and the decompression using javascript at the client's on the browser side. I know plain text(ie html) can be compressed easily up to 90% but perhaps you could even grab some image compression algorithms that just water down already compressed image formats like jpg and gifs into lower res pics.

    Could this be done?
     
    wormy, Aug 29, 2006 IP
  2. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Short answer: no.
    Although theoretically it MAY be possible, but I imagine the javascript code for doing the decompressing would be so huge and the decompressing process would be very slow that it's not even worth considering.

    What could be done instead is to do this on the lower level. With Apache, there's modules called mod_gzip and mod_deflate which deal with this compression. Not sure about other web servers, but I guess most should have similar capabilities, whether by default or as an extension (or module or whatever).

    How it works is, when requesting for a file, browser includes in the request header what compression methods it supports (gzip or deflate or both. probably there are others too, although these 2 are the most common). If the web server is configured to support that compression method, it will then compress the files before sending it to the browser. The browser will then uncompress the files on the client side.

    Just as a side note, usually on the server side, the compression is explicitly configured so that it doesn't compress binary files (e.g.: image files) because they are essentially already compressed, and attempting to compress it further would just be a waste of resources, and potentially even increase the size of the file.
     
    phper, Aug 29, 2006 IP
  3. wormy

    wormy Active Member

    Messages:
    1,112
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #3
    http://www.onspeed.com

    These people seem to have made a business out of compressing binary files for the purpose of boosting percieved speed. I was thinking there may be a few tricks to duplicate some of their concepts.
     
    wormy, Aug 30, 2006 IP