How to handle loading of LARGE JSON files How to handle loading of LARGE JSON files json json

How to handle loading of LARGE JSON files


JSON is incredibly redundant so it compresses well, which is then decompressed on the client.

JavaScript implementation of Gzip

Alternatively you could chunk the data up into 1 MB chunks to be sent over one at a time. Also the user probably can't interact with 120 MB of data at a time, so maybe implement some sort of level of detail system?


If you control the web server sending the data, you could try enabling compression of json data.

This is done by adding the following in applicationhost.config (IIS 7):

<system.webServer>    <urlCompression doDynamicCompression="true" />    <httpCompression>      <dynamicTypes>        <add mimeType="application/json" enabled="true" />        <add mimeType="application/json; charset=utf-8" enabled="true" />              </dynamicTypes>    </httpCompression></system.webServer>

You would then need to restart the App pool for your app.

Source


A few things you might consider:

  1. Is your server compressing the file before sending?

  2. Does this data change often? If it does not, you could set your expires header to a very long time, so the browser could keep it in cache. It wouldn't help on the first page access, but on subsequent ones the file wouldn't have to be loaded again.

  3. Is there a lot of repeating stuff in your json file? For instance, if your object keys are long, you could replace them with shorter ones, send, and replace again in the browser. The benefits will not be that great if the file is compressed (see item 1) but depending on your file it might help a little.

  4. Is all this data consumed by the browser at once? If it's not, you could try breaking it down into smaller pieces, and start processing the first parts while the others load.

But the most important: are you sure JSON is the right tool for this job? A general purpose compression tool can only go so far, but if you explore the particular characteristics of your data you might be able to achieve better results. If you give more details on the format you're using we may be able to help you more.