Compress on client

Hi,

It is possible to compress a string(JSON) on the client side before sending it to the server?

Any hints?

thanks in advance,

Omar Zelaya

There is at this moment not a function in TMS WEB Core built-in for compressing text.
Maybe this is an interesting JavaScript library you can use client-side for this:

Hi,

Thanks for the tip. Do you know any similar for Brotli compression.

Thanks in avance,

Omar Zelaya

Hi,

Any hint how to compess content for XData server can uncompress it automatically?

On VCL I use the following
HttpClient.OnSendingRequest := procedure(Req: THttpRequest)
begin
...
LZip := TZCompressionStream.Create(clDefault, OutStream);
LZip.Write(Req.ContentBuffer^, Req.ContentLength);
LZip.Free;
SetLength(NewContent,OutStream.Size);
Move(OutStream.Bytes[0],NewContent[0],OutStream.Size);
Req.SetContent(NewContent);
Req.Headers.SetValue('content-encoding','deflate');
...
end;

Thanks in advance,

Omar Zelaya

There is no equivalent for that from TMS Web Core applications.

Hi,

On event XDataWebConnection.OnRequest ther is now to way to access Args.Request.Content(Content buffer) to compess it using a java lib, modify the request content buffer and set the required headers?

Thanks in advance,

Omar Zelaya

Yes, you can do that, but that's up to you, there is no built-in routines for compressing. But yes, you can simply set the Content property of the request to a new value.

Hi,

Can you please provide a code sample or hint on how to modifiy the content. I have checked Args.Request.Content and is a JSValue Variable.

Thanks in advance,

Omar Zelaya

A JSValue can simply receive anything. Just set any value to it and that's what is going to be used in the internal xhr.send method, as explained here:

How to compress the data and get the value is up to you.