mardi 30 janvier 2018

What's the effective way for compress URL of 1200-1500 characters?

I have many problematics in this question. I have to compress URI which doesn't have a static architecture then it's hard to do a things like that :

repos=aaa,bbb,ccc&
labels=ddd,eee,fff&
milestones=ggg,hhh,iii&
username=kkk&
show_open=0&
show_closed=1&
show_commented=1&
show_uncommented=0

extract:

aaa,bbb,ccc|ddd,eee,fff|ggg,hhh,iii|kkk|0110

The request are made a little bit in a GraphQL way so we send structure and have answers for this structure. For the moment the compression we use is juste changing some wording which are in all requests (function: is f:, ..). We want to do a generic compression, not something we have to maintain if the architecture change(in the following example we don't want to change quizz.campaign to #12 per example). We do this kind of request one to two times per connection so what is the most expensive between download a library at the connection which will compress my request from 1500 to maybe 300 characters OR do some generic compression like change the [ to ( which will compress from 1500 to 900.

The generic compression could look like something like that:

str.replace(/\*/g, "%#111")
        .replace(/\!/g, "%#222")
        .replace(/\(/g, "%#333")
        .replace(/\)/g, "%#444")
        .replace(/\~/g, "%#555")
        .replace(/\_/g, "%#666")
        .replace(/\'/g, "%#777")
        .replace(/\,/g, "*")
        .replace(/\:/g, "!")
        .replace(/\[/g, "(")
        .replace(/\]/g, ")")
        .replace(/\{/g, "~")
        .replace(/\}/g, "_")
        .replace(/\"/g, "'")
        .replace(/\%#111/g, ",")
        .replace(/\%#222/g, ":")
        .replace(/\%#333/g, "[")
        .replace(/\%#444/g, "]")
        .replace(/\%#555/g, "{")
        .replace(/\%#666/g, "}")
        .replace(/\%#777/g, '"');

The json of a request looks like that:

    [{
    "f": "find-qzc-by-id",
    "k": "qzcpn",
    "a": {
        "quizz.campaign/id": "quizz-kdfjdslk"
    },
    "n": [{
        "f": "quizz.campaign/activeQuizzQuestions",
        "k": "quizz.campaign/activeQuizzQuestions",
        "n": ["fanQuestion/id", "fanQuestion/questionText", "fanQuestion/questionType", {
            "f": "fanQuestion/choices",
            "k": "fanQuestion/choices",
            "n": ["quizz.question.choice/bgImg", "fanQuestion.choice/id", "fanQuestion.choice/adminLabel", "fanQuestion.choice/text"]
        }, "bs.model/scid", "bs.model/uiConfig"]
    }, "quizz.campaign/id", "quizz.campaign/gameLogic", "quizz.campaign/quizzConfig", "quizz.campaign/bgImg", "quizz.campaign/previewImage", "quizz.campaign/title", "quizz.campaign/description", "campaign/publicOrganizerName", {
        "f": "campaign/organization",
        "k": "campaign/organization",
        "n": ["org/id"]
    }, "campaign/bsCpnType", "bs.model/scid", "bs.model/uiConfig", "bs.model/bsCustomContent", "bs.time/created", "bs.model/nl"]
}]

Then the encoded request looks like that :

?q=%5B%7B%22f%22%3A%22find-qzc-by-id%22%2C%22k%22%3A%22qzcpn%22%2C%22a%22%3A%7B%22quizz.campaign%2Fid%22%3A%22quizz-kdfjdslk%22%7D%2C%22n%22%3A%5B%7B%22f%22%3A%22quizz.campaign%2FactiveQuizzQuestions%22%2C%22k%22%3A%22quizz.campaign%2FactiveQuizzQuestions%22%2C%22n%22%3A%5B%22fanQuestion%2Fid%22%2C%22fanQuestion%2FquestionText%22%2C%22fanQuestion%2FquestionType%22%2C%7B%22f%22%3A%22fanQuestion%2Fchoices%22%2C%22k%22%3A%22fanQuestion%2Fchoices%22%2C%22n%22%3A%5B%22quizz.question.choice%2FbgImg%22%2C%22fanQuestion.choice%2Fid%22%2C%22fanQuestion.choice%2FadminLabel%22%2C%22fanQuestion.choice%2Ftext%22%5D%7D%2C%22bs.model%2Fscid%22%2C%22bs.model%2FuiConfig%22%5D%7D%2C%22quizz.campaign%2Fid%22%2C%22quizz.campaign%2FgameLogic%22%2C%22quizz.campaign%2FquizzConfig%22%2C%22quizz.campaign%2FbgImg%22%2C%22quizz.campaign%2FpreviewImage%22%2C%22quizz.campaign%2Ftitle%22%2C%22quizz.campaign%2Fdescription%22%2C%22campaign%2FpublicOrganizerName%22%2C%7B%22f%22%3A%22campaign%2Forganization%22%2C%22k%22%3A%22campaign%2Forganization%22%2C%22n%22%3A%5B%22org%2Fid%22%5D%7D%2C%22campaign%2FbsCpnType%22%2C%22bs.model%2Fscid%22%2C%22bs.model%2FuiConfig%22%2C%22bs.model%2FbsCustomContent%22%2C%22bs.time%2Fcreated%22%2C%22bs.model%2Fnl%22%5D%7D%5D

If you think that a library would be the better way for the cost question, do you have some recommandations for compress in js and decompress on the jvm ? Thanks.




Aucun commentaire:

Enregistrer un commentaire