我在这个问题上有很多问题。 我必须压缩没有静态架构的URI,然后很难做到这样的事情:
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
提取物:
aaa,bbb,ccc|ddd,eee,fff|ggg,hhh,iii|kkk|0110
请求以GraphQL方式进行,因此我们发送结构并获得此结构的答案。目前我们使用的压缩是juste更改了所有请求中的一些措辞(函数:是f:,..)。 我们想要进行通用压缩,而不是在架构发生变化时我们必须维护的东西(在下面的示例中,我们不想将quizz.campaign更改为每个示例的#12)。我们每个连接都会做一到两次这样的请求,所以最便宜的在连接下载一个库,将我的请求从1500压缩到300个字符 OR 做一些通用压缩,比如改变[to(将从1500压缩到900。
通用压缩看起来像这样:
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, '"');
请求的json看起来像这样:
[{
"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"]
}]
然后编码的请求看起来像:
?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
如果您认为库是成本问题的更好方法,那么您是否有一些关于js压缩和jvm解压缩的建议?感谢。
答案 0 :(得分:0)
简单地使用POST并不需要OPTION请求,请检查https://stackoverflow.com/a/27924344/158037
如果你真的想使用压缩,你不必在JS中这样做。 对于方向"服务器 - >浏览器"启用deflate压缩(" Accept-Encoding:deflate",gzip或br)应该足够了,并且不需要对代码进行任何更改,也许只是在服务器配置中启用它(apache,tomcat,无论你是什么使用)。
对于"浏览器 - >服务器"实际上使用HTTP 2.0的查询字符串是最简单的解决方案,因为它压缩了所有标题,包括" Path:"。