Solved

Compress/Decompress strings with javascript

Posted on 2003-11-12
17
14,708 Views
Last Modified: 2009-12-13
Hi,

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.
0
Comment
Question by:hveld
  • 5
  • 4
  • 2
  • +4
17 Comments
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
Is this link something for you:
http://www.websiteoptimization.com/speed/9/

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,
NetGroove


0
 
LVL 16

Expert Comment

by:_nn_
Comment Utility
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.
0
 

Author Comment

by:hveld
Comment Utility
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.
0
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
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.

0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
PS: There is no zip for javascript if that is what you hoped
0
 
LVL 11

Expert Comment

by:Zontar
Comment Utility
Servers will send files with gzip compression automatically provided both they and the client understand it.
0
 
LVL 11

Expert Comment

by:Zontar
Comment Utility
BTW, if you're storing THAT much data in .js files, it's time to start looking into using a database.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Yes - but I just wanted to make sure hveld did not expect some binary compression/decompression under his control
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:_nn_
Comment Utility
FYI NetGroove, I don't know for other daemons, but for Apache :
- http://httpd.apache.org/docs-2.0/mod/mod_deflate.html
- http://sourceforge.net/projects/mod-gzip/
0
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
Thanks _nn_
0
 

Author Comment

by:hveld
Comment Utility
well what I need is possible, take a look at
htmlzip.com

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.
0
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
Look at bottom of this page:
http://htmlzip.com/examples_z.htm

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.

0
 

Author Comment

by:hveld
Comment Utility
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.
0
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
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?
0
 

Author Comment

by:hveld
Comment Utility
yes, please make an offer.
My email is <Email removed by GhostMod, CS Moderator>
0
 
LVL 16

Expert Comment

by:jaysolomon
Comment Utility
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.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
Comment Utility
PAQed - no points refunded (of 500)

GhostMod
Community Support Moderator
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now