1

I'm working on an AJAX application that uses Knockout and Sammy for AJAX history. The application uses a set of filters, sort options and pagination to let the user search trough 35000 records.

Currently the URL hash is in the following form:

http://domain/Search/{SearchTerms}/PageIndex

For example:

http://localhost/search/#0%20-%205%C4%80square%20meter/1

The search terms are parsed on the server to match them to the available filters. I can't use an Id or something because the filter set is rebuild each day (when backend data updates) and the only thing that stays the same is the description.

This is the javascript code to build the hash:

var hash = '';

ko.utils.arrayForEach(self.SelectedItems(), function (item) {
    hash = hash + item.Description + ' ';
});

hash = encodeURIComponent($.trim(hash));
hash = hash + '/' + self.HuidigePagina();

location.hash = hash;

The problem is that joining all the item descriptions can become really long. Is there a way I can compress this part and then decompress it when I send it to the server in javascript?

I've found some answers here on stackoverflow that uses LZW compression, but it didn't give me my original string back.

Wouter de Kort
  • 39,090
  • 12
  • 84
  • 103
  • 1
    Why you don't want to use POST method instead of GET?(max get 255) – Oyeme May 08 '12 at 07:38
  • It's more a readability issue. Our users freak out when they see a url that long :P – Wouter de Kort May 08 '12 at 07:41
  • When your search query is so long that it needs to compressed, then probably the app is badly written. I mean using `item.Description` as a search field?? What is this?? Google?? :) – freakish May 08 '12 at 10:09
  • @freakish Description is the only thing that's consistent. Other fields will change daily. I could come up with mapping the description to an id and rewriting a lot of code but I was wondering if I could do it more easily by compressing the hash – Wouter de Kort May 08 '12 at 11:03
  • @WouterdeKort Yeah, I understand this. But you should know that this is wrong. I mean what's an ID? ID is a string/number/object/anything which **identifies** your database object. If it changes frequently then what is the point in calling it ID? I mean `item.description` **is** an ID in your case. The only problem is that it is big. So developing the app the way you are doing now will be even more problemous in the future. I suggest you redesign it and use shorter IDs. – freakish May 08 '12 at 12:09

0 Answers0