Compress/Decompress strings with javascript


I keep really big amounts of data in .js files. Sometimes js files become 700-800 K or even more, which is a problem for slow connections.

Is there any way to compress the data stored in the .js file (let's say it's one huge string) and then decompress it through javascript on the visitor's machine?
What I need is the size to be reduced to max. 40% of the initial size, and the decompression to be relatively fast.

The compression might be slow and not in javascript, actually I would prefer VB(VBA) compression because the data will be generated from Excel.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Is this link something for you:

By the way, I do not believe you will save significant time. The time you get in transfer you will loose in decompression with the option to have bad maintainable sources.
Better are the upper recommendation of source compaction with regular means.

Good luck,

When it comes to text files (any form, HTML, js, css, whatever) of sizes of 100K or more, it should be handled at the protocol level. Well, for 700-800K, I'd still run a first "pass" with NetGroove's recommendation, e.g. some reasonable source code compaction would probably not hurt. Though, modern browsers accept compressed contents in gzip and/or deflate format. Both compression algorythms should be able to get very comfortable compression ratios on text files. And everything would stay transparent for the developer and the 'netsurfer'. It's just a matter of running and configuring a webserver that can compress on the fly. I still don't understand why the EE site itself doesn't use it... ah sorry, off-topic.
hveldAuthor Commented:
Thnx NetGroove but this link contains info/tools to optimize or compress scripts - mainly by removing everything that is not needed for the script to work.
What I need is to compress a string without removing anything from it - that is, a true compression. Later on when the string is  restored(decompressed) , it should be an exact copy of the input string.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Sorry, but now I also think like _nn_ that you are wasting your time finding an easy method that YOU can do compression by script and decompression on browser side.
I do not know how this content compression by web server is done, but I know that most transmission hardware, like modems or network routers, already do the block content compression without any interference to upper layers.
Search for JavaScript compression in Google and you will see that you get Minutes! per kilobyte for compression and decompression with script methods. This is a task for hardware layers.

Michel PlungjanIT ExpertCommented:
PS: There is no zip for javascript if that is what you hoped
Servers will send files with gzip compression automatically provided both they and the client understand it.
BTW, if you're storing THAT much data in .js files, it's time to start looking into using a database.
Michel PlungjanIT ExpertCommented:
Yes - but I just wanted to make sure hveld did not expect some binary compression/decompression under his control
FYI NetGroove, I don't know for other daemons, but for Apache :
Thanks _nn_
hveldAuthor Commented:
well what I need is possible, take a look at

This app compresses html files and reduces their size a lot, sometimes to 1/4 of the original size(for files larger than 30 K). Obviously this can't be done by simply removing the useless characters from the source.
I think it uses a javascript implementation of some compression algorithm - that's what I need. Unfortunately it can't compress script files and compressed html files sometimes don't work, but there is a way to compress text with javascript.

As for the other suggestions, I can't use them because of my host.
Look at bottom of this page:

You will see two things: compression brings NOTHING (7105 bytes > 6026 bytes), but brings problems on browser side, like slow decompression.

If you want that algorithm for you, then you can pay for it, either to that company or to me. From me you will get the sources.

hveldAuthor Commented:
Well if you test it with a 100 K or bigger file there will be a difference. And I need to compress big files, like 700-800 K.
I would have bought the app but it can't compress script files, and compressed html files very often do not work. But I didn't notice a slow decompression. For big files, it's takes less time than the time needed to download the uncompressed file.
So you are thinking about a way that I could make you an offer to implement that compression algorithm for javascript files, for money, right?
hveldAuthor Commented:
yes, please make an offer.
My email is <Email removed by GhostMod, CS Moderator>
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ - no points refunded

Please leave any comments here within the next four days.

EE Cleanup Volunteer
PAQed - no points refunded (of 500)

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.