Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  72] [ 5]  / answers: 1 / hits: 8469  / 11 Years ago, tue, december 31, 2013, 12:00:00

I'm trying to load a json file using angular (v1.2.6):



$http.get('myfile.json').success(function(data) { ... }


This works fine, except when I create a (static) compressed version of the file on the server, and try to load 'myfile.json.gz' instead (to reduce the loading time).



The request headers seem correct (Chrome 31.0 on Mac) (as stated here and here):



Accept: application/json, text/plain, */*
Accept-Encoding: gzip,deflate,sdch


while the response headers contain:



Connection: close
Accept-Ranges: bytes
Content-Length: 702468
Content-Type: application/x-gzip
Content-Encoding: gzip


However, the content is not automatically decompressed by the client browser, as I understand it should be. data.length is ~700Kb instead of the original uncompressed ~3Mb.



Although this one post suggests it needs to be done manually, I understand decompression should be automatic and transparent.



My question is, should it be decompressed automatically? and why isn't it the case here?


More From » json

 Answers
4

Your content type should not be application/x-gzip* it should stay :
application/json



The content encoding is enough to say to the browser that the content is zipped.



What HTTP server are you running ?
You should configure it in order to return the correct mime type, regardless of the .gz extension.


[#49104] Monday, December 30, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cindyanyssam

Total Points: 483
Total Questions: 94
Total Answers: 100

Location: Barbados
Member since Sat, May 28, 2022
2 Years ago
;