Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 14950
  • Last Modified:

Compress/Decompress strings with javascript

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
hveld
Asked:
hveld
  • 5
  • 4
  • 2
  • +4
1 Solution
 
NetGrooveCommented:
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
 
_nn_Commented:
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
 
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
NetGrooveCommented:
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
 
Michel PlungjanIT ExpertCommented:
PS: There is no zip for javascript if that is what you hoped
0
 
ZontarCommented:
Servers will send files with gzip compression automatically provided both they and the client understand it.
0
 
ZontarCommented:
BTW, if you're storing THAT much data in .js files, it's time to start looking into using a database.
0
 
Michel PlungjanIT ExpertCommented:
Yes - but I just wanted to make sure hveld did not expect some binary compression/decompression under his control
0
 
_nn_Commented:
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
 
NetGrooveCommented:
Thanks _nn_
0
 
hveldAuthor Commented:
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
 
NetGrooveCommented:
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
 
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.
0
 
NetGrooveCommented:
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
 
hveldAuthor Commented:
yes, please make an offer.
My email is <Email removed by GhostMod, CS Moderator>
0
 
jaysolomonCommented:
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
 
GhostModCommented:
PAQed - no points refunded (of 500)

GhostMod
Community Support Moderator
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 4
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now