I'm facing an issue with compressing my request - instead of reducing the size, it seems to be increasing it:
const requestData = LZString.compress(JSON.stringify({ data: bigBase64StringHere }));
await axios.post("api-endpoint", requestData, {
headers: { "Content-Type": "text/plain" },
});
When I compare the original string and the compressed one, I noticed that the compressed one is larger (original 400K vs compressed 500K). However, when calculating their sizes, the compressed one is actually half of the original size (original 800K vs compressed 330K).
Logging using console.log
:
Uncompressed size:
https://i.sstatic.net/pqRAN.png
Compressed size:
https://i.sstatic.net/cDw6o.png
Logging using sizeof:
https://i.sstatic.net/5nn7l.png
(top uncompressed, bottom compressed)
Despite the compression seemingly working based on these comparisons, could it be that the Content-Length header is not accurately reflecting the actual request size?
This situation raises questions about the effectiveness of the compression method. Find more information at pieroxy.net/blog/pages/lz-string/demo.html.