gzip压缩的JSON文件不DECOM pressing [英] Gzipped JSON file not decompressing

查看:154
本文介绍了gzip压缩的JSON文件不DECOM pressing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的存储服务器作为file.json大(30MB +)JSON文件。使用jQuery的的getJSON(HTTP://site/file.json)功能,它工作得很好。但是,正如你可能会想到一个JSON响应的下载30MB值得花费时间的体面的卡盘。

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 think downloading 30MB worth of a JSON response takes a decent chuck of time.

相反,我现在将其存储为gzip压缩文件(file.json.gz)的削减下来,只是1MB下!我想用的getJSON(HTTP://site/file.json.gz)做同样的事情,但它看起来就像是浏览器的不可以 DECOM pressing的GZIP D响应,所以解析它不能正常工作。

Instead I'm now storing them as Gzip'd files (file.json.gz) which cuts them down to just under 1MB! I'd like to do the same thing by using getJSON("http://site/file.json.gz"), but it looks like browsers are not decompressing the GZIP'd response, so parsing it doesn't work.

那么,有没有什么办法让jQuery的或浏览器DECOM preSS一个已经使用GZIP如file.json.gz COM pressed静态JSON文件?

So, is there any way to get jQuery or the browser to decompress a static JSON file that's been compressed using GZIP such as file.json.gz?

BTW:保存的文件是COM pressed正常。如果我手动DECOM preSS他们我得到的30MB +有效的JSON文件。

BTW: The saved files are compressed properly. If I manually decompress them I get the 30MB+ valid JSON file.

推荐答案

浏览器不会自动DECOM preSS只是任何COM pressed数据跨它们运行。服务器有告诉流只有COM pressed运输浏览器和它需要DECOM pressed处理(否则你将无法在下载和保存COM pressed档案之前所有!)你需要让你的Web服务器发送合适的标题(内容编码),但是做检查浏览器支持COM pression首先这样做(在Accept-Encoding头之前)。大多数网络服务器也可以gzip压缩动态的东西给你,除非这是太大的性能损失。

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.

不知怎的,我有你将有更多的麻烦解析的感觉,很多JSON的浏览器不是检索它...

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

这篇关于gzip压缩的JSON文件不DECOM pressing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆