0

I've enabled gzip on my php scripts by doing this:

<? ob_start("ob_gzhandler"); 
?>
<?php
header('Content-Type: application/json');
header('Accept-Encoding: gzip');

/* Request data, transform it, json_encode it, echo */

?>
<? ob_flush(); ?>

This has been working on a couple of hosts, but when I moved to Hosting24, it simply wont work.

I have also enabled 'Compress all content' in cPanel's optimize website section, along with editing the .htaccess file to something like this: https://stackoverflow.com/a/8262235/2237587

Hosting24 has assured me of this:

Our servers support mod_gzip, mod_deflate by default. 

To use GZIP, please call the function ob_start("ob_gzhandler"); at the top of your script. Also remember to call the function ob_flush(); at end

I am doing this, but it does not work for Hosting24. When I use the same script on another service (tested on 000webhost and Arvixe), the response is compressed.

What can I try next to get it compressed, to be honest I have no idea why it's not working already.

Community
  • 1
  • 1
Simon
  • 1,354
  • 1
  • 14
  • 18
  • Thanks for the suggestion, but it didn't work – Simon May 21 '13 at 06:54
  • GZIP works when I set the content type as text/html, but I need the content type to be application/json to work nicely with AFNetworking. Is this a problem with Hosting24 not accepting application/json as the content type? – Simon May 21 '13 at 08:51

1 Answers1

0

Replacing this:

header('Content-Type: application/json');

with

header('Content-Type: text/javascript');

fixed the problem. Not sure if this is a problem with Hosting24 or not. text/javascript allows me to use the json request of AFNetworking still so i'm happy with result.

Simon
  • 1,354
  • 1
  • 14
  • 18