Gzipped JSON file not decompressing

前端 未结 3 889
天命终不由人
天命终不由人 2020-12-15 19:43

I have large (30MB+) JSON files stored on my server as file.json. Using jQuery\'s getJSON(\"http://site/file.json\") function it works just fine. But, as you\'d probably thi

3条回答
  •  我在风中等你
    2020-12-15 20:31

    Browsers don't automatically decompress just any compressed data they run across. The server has to tell the browser that the stream is only compressed for transport and it needs to be decompressed before processing (otherwise you wouldn't be able to download and save compressed archives at all!) You need to make your web server send the appropriate headers (Content-Encoding), but do check that the browser supports compression in the first place before doing that (the Accept-Encoding header). Most webservers can also gzip things for you on the fly, unless that's too big of a performance hit.

    Somehow I have the feeling you're going to have more trouble parsing that much JSON on the browser than retrieving it...

提交回复
热议问题