1

I store our data in a json file and use javascript to load it like "$.getJson(json_path)".

However, our data becomes larger and larger. Transferring such a file over network takes some time if the network condition is not good enough.

I found compressing the json file into a zip file makes its size become 1/10. Is there any way for me to load a compressed json file using javascript?

Thank you.

Max
  • 13
  • 2
  • 2
    Compression is handled by browser. Your server serves compressed files. What back-end you are using? Maybe you can use some kind of js database/split to different files? – Justinas Jun 29 '20 at 06:27
  • Thanks. I don't use a backend to handle the data issue. I just put the json file on the server and use javascript to load it. The data in the json file will be shown in a bootstrap-table using client pagination. I know server-side pagination will solve the efficiency problem but it involves search and sort. As I'm new to web development, I don't know how to implement that. That's why I want to solve the problem with the compressed file. – Max Jun 29 '20 at 06:45
  • so your server - what is it? – Justinas Jun 29 '20 at 06:51
  • It is an nginx server. – Max Jun 29 '20 at 06:55

1 Answers1

1

You can get a compressed file over the network, decompress it and load it with

compressed-json package and jQuery.

const cjson = require('compressed-json')

const restored = cjson.decompress("Your compressed file")

jQuery.getJSON(restored) or JSON.parse(restored)
AvivBS
  • 66
  • 3
  • Thanks very much. That's exactly what we want. Will try. – Max Jun 29 '20 at 06:49
  • I would use zip, Gzip is the standard file compression for Unix and Linux systems. Gzip is faster than ZIP while compressing and decompressing. ZIP is an archiving and compression tool, all in one, while Gzip needs the help of Tar command to archive files. Gzip can save more disk space than ZIP compression applications. If I helped you please leave a upvote. – AvivBS Jun 29 '20 at 06:54
  • Thanks. Does compressed-json support zip compression? – Max Jun 29 '20 at 07:01