CodeIgniter Forums

Full Version: GZip Compression for Website with Ajax
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
Why not just rely on mod_deflate (an .htaccess solution)?
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.
Try this:

1. Open php.ini
2. Add zlib.output_compression=On
3. Save
4. Reset server (if needed)
(04-20-2017, 12:04 PM)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...
Enabling compression should not break AJAX responses. Did you check your error log?
Thanks guys, it work, thanks for the useful information!
compression can sometime break functionality particularly ajax therefore take proper care when applying gzip.