I'm trying to narrow down some weirdness going on with my AJAX calls. My PHP scripts have this at the start:
Works great with HTML. But are there any problems with doing it with application/json data? Any browser issues anyone is aware of?
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
You should also check the headers sent by the browser for proper accept-encoding header before sending gzipped content... that is,
You can give out gzipped content whenever the browser specifies
Accept-Encoding request header. In that case, there is no difference between JSON and HTML and no problems will be caused whatsoever.
Instead of enabling compression in PHP, I would enable compression in Apache (using mod_deflate) so that you can check for various incompatible browsers and only send compressed data for the browsers that accept it and handle it correctly.