简体   繁体   English

将文本从html压缩和解压缩到服务器,反之亦然

[英]compressing and decompressing Text from html to server and vice-versa

We are going to write a feature on my system that will require a very massive user http post and http response, probably millions of requests/response with just some bytes each ( sending and getting with ajax and json ) 我们将在系统上编写一项功能,该功能将需要非常庞大的用户http帖子和http响应,可能需要数百万个请求/响应,每个请求/响应仅包含一些字节(使用ajax和json发送和获取)

but that's not enough I need to find a way to compress the data with java script and decompress on the server side ( .net or java servlets ) and also compress on the server and decompress with javascript. 但这还不够,我需要找到一种方法来使用Java脚本压缩数据并在服务器端(.net或Java servlet)进行解压缩,还需要在服务器上进行压缩并使用javascript解压缩。

It seems silly save such bytes, but I want to be prepared for the worst. 保存这样的字节似乎很愚蠢,但我想为最坏的情况做好准备。

Any directions? 有方向吗? just post what you think, let's share our thoughts 只需发表您的想法,让我们分享我们的想法

thanks 谢谢

Ed 埃德

Is a server-level implementation of zlib compression not good enough for your use case? zlib压缩的服务器级实现是否不足以满足您的用例? That'd be the most simple and reliable way to get compression working. 那将是使压缩工作最简单,最可靠的方法。 All the most common web servers and browsers support zlib compression out of the box. 所有最常见的Web服务器和浏览器均支持开箱即用的zlib压缩。

You can use HTTP Compression suppoerted by major web servers, app servers and browsers. 您可以使用主要Web服务器,应用程序服务器和浏览器支持的HTTP压缩。 While you do that, note that IE has historically been very buggy in that area, so make sure that it works in multiple versions of IE. 在执行此操作时,请注意,IE在该领域历来是个漏洞,因此请确保它可以在IE的多个版本中使用。 For apache, you can use mod_deflate. 对于apache,可以使用mod_deflate。 Jetty & Tomcat have their own versions of a GZIP filter. Jetty和Tomcat具有自己的GZIP过滤器版本。 Compressing/Decompressing in Javascript will be cumbersome. 用Javascript进行压缩/解压缩会很麻烦。 I am not aware of any libraries available in JS that can help you. 我不知道JS中有任何可以帮助您的库。

Performance questions require you to try and measure to get any reasonable answer. 性能问题要求您尝试并采取措施以获取任何合理的答案。

In your case I would carefully look at raw message and see where bytes are - I bet that for tiny data packets most of the bytes would be in headers, so compression of content will give you no benefit. 在您的情况下,我会仔细查看原始消息并查看字节在哪里-我敢打赌,对于微小的数据包,大多数字节将位于标头中,因此压缩内容不会给您带来任何好处。 It is your system - look at your requests and see where you can get decrease size of packets. 这是您的系统-查看您的请求,看看在哪里可以减少数据包的大小。

Note that often you need to send user's authentication with the request - as result your request will have fixed size, usually non-compressible chunk of data in it. 请注意,通常您需要通过请求发送用户的身份验证-结果,您的请求将具有固定的大小,通常是不可压缩的数据块。

In Java you could use the java.util.zip package which should provide you with compress-/decompress methods. 在Java中,您可以使用java.util.zip软件包,该软件包应为您提供compress // decompress方法。

For JavaScript I found this tutorial . 对于JavaScript,我找到了本教程 Or you could implement your own method by replacing all unicode characters of the byte-stream like this: 或者,您可以通过替换字节流的所有unicode字符来实现自己的方法,如下所示:

Your message: 你的信息:
AABCCC
Unicode Bytes: Unicode字节:
0x41 0x00 0x41 0x00 0x42 0x00 0x43 0x00 0x43 0x00 0x43 0x00
compressed by leaving out the 0x00 : 通过省略0x00进行压缩:
0x41 0x41 0x42 0x43 0x43 0x43
even more by leaving out doubles: 通过省略双打来获得更多:
2 0x41 1 0x42 3 0x43

Even though it doesn't look very impressive right now, there might be one or two requests that could profit from this compression. 即使现在看起来并不十分令人印象深刻,但可能会有一两个请求可以从这种压缩中受益。 Although it is really important for the algorithm to be very effective and sufficient. 尽管算法非常有效和充分确实很重要。 Since you are talking about 'millions' of requests. 因为您正在谈论“数百万”的请求。 One big request could profit from this compression, but many small requests could be very inefficient. 一个大请求可以从这种压缩中受益,但是许多小请求可能效率很低。

Sorry I can't provide you with a complete solution, but maybe this brings you a little closer. 抱歉,我无法为您提供完整的解决方案,但这也许会使您更接近一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM