Solved

Compress/Decompress strings with javascript

Posted on 2003-11-12
17
14,744 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
ID: 9730845
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_
ID: 9731137
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
ID: 9731208
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 10

Expert Comment

by:NetGroove
ID: 9731414
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
ID: 9731924
PS: There is no zip for javascript if that is what you hoped
0
 
LVL 11

Expert Comment

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

Expert Comment

by:Zontar
ID: 9732025
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
ID: 9732035
Yes - but I just wanted to make sure hveld did not expect some binary compression/decompression under his control
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9732089
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
ID: 9732169
Thanks _nn_
0
 

Author Comment

by:hveld
ID: 9786688
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
ID: 9787053
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
ID: 9798399
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
ID: 9800408
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
ID: 9802467
yes, please make an offer.
My email is <Email removed by GhostMod, CS Moderator>
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10434316
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
ID: 10472203
PAQed - no points refunded (of 500)

GhostMod
Community Support Moderator
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

813 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

18 Experts available now in Live!

Get 1:1 Help Now