I'm trying to narrow down some weirdness going on with my AJAX calls. My PHP scripts have this at the start:
ob_start("ob_gzhandler");
Works great with HTML. But are there any problems with doing it with application/json data? Any browser issues anyone is aware of?
Compressing with gzip As text data, JSON data compresses nicely. That's why gzip is our first option to reduce the JSON data size. Moreover, it can be automatically applied in HTTP, the common protocol for sending and receiving JSON.
JSON responses are not natively compressed. Response compression can optimize network bandwidth usage and increase application responsiveness.
Though JSON is a concise format, it is also better used over a slow network in compressed mode.
The Accept-Encoding header is used for negotiating content encoding. Accept-Encoding: gzip, deflate. The server responds with the scheme used, indicated by the Content-Encoding response header. Content-Encoding: gzip. Note that the server is not obligated to use any compression method.
I don't think so... I've used static files stored as gzipped JSON before, and it worked fine with AJAX.
edit: I checked my php script and the only thing special I did was to include these headers:
Content-Encoding: gzip
Content-Type: text/plain
If I remember right, whenever I tried to change the Content-Type to something that would indicate JSON, the client had trouble.
Some older browsers, like certain versions of IE6, screw up gzipped content, especially js content.
Just check that your server sends proper content-encoding header, that is
Content-Encoding: gzip
You should also check the headers sent by the browser for proper accept-encoding header before sending gzipped content... that is,
Accept-Encoding: gzip,deflate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With