CodeIgniter Forums
GZip Compression for Website with Ajax - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: GZip Compression for Website with Ajax (/showthread.php?tid=67889)



GZip Compression for Website with Ajax - Waschi - 04-20-2017

Hi everyone,
i would like to enable gzip-compression for my website.
But than i have a problem with my ajax-requests.
E.g i run into js error (because i get a compressed json).
I guess i cant handle this with jQuery, so is it possible to disable the gzip compression for some controller-functions?

Eg. Controller/func1 = compression on
      Controller/func2 = compression off

Thank you !  Smile

//Im not sure if "Best Practices" or "General Help" is the correct section for this.


RE: GZip Compression for Website with Ajax - Diederik - 04-20-2017

Why not just rely on mod_deflate (an .htaccess solution)?


RE: GZip Compression for Website with Ajax - antony - 04-20-2017

What do you mean by "i run into js error (because i get a compressed json)"?
Json should remain valid even if compressed.

Could you provide an example of what a request looks like compressed (invalid) and uncompressed (valid), as well as your javascript code which can't parse the compressed code.


RE: GZip Compression for Website with Ajax - AzrielOmega - 04-20-2017

Try this:

1. Open php.ini
2. Add zlib.output_compression=On
3. Save
4. Reset server (if needed)


RE: GZip Compression for Website with Ajax - Waschi - 04-27-2017

(04-20-2017, 11:04 AM)antony Wrote: What do you mean by "i run into js error (because i get a compressed json)"?
Json should remain valid even if compressed.

Could you provide an example of what a request looks like compressed (invalid) and uncompressed (valid), as well as your javascript code which can't parse the compressed code.
If "compress_output" = false, than i get a valid json back.
If "compress_output" = true, i dont get any data back from the api. (But get 200 OK from Server)

@Diederik Thank you, that work. 

@AzrielOmega Mhh that didnt effect the loading-size of my page...


RE: GZip Compression for Website with Ajax - spjonez - 04-27-2017

Enabling compression should not break AJAX responses. Did you check your error log?


RE: GZip Compression for Website with Ajax - savitasandeep - 06-13-2017

compression can sometime break functionality particularly ajax therefore take proper care when applying gzip.