Welcome Guest, Not a member yet? Register   Sign In
GZip Compression for Website with Ajax
#1

(This post was last modified: 04-20-2017, 06:21 AM by Waschi.)

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.
Reply
#2

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

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.
Reply
#4

Try this:

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

(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...
Reply
#6

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

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




Theme © iAndrew 2016 - Forum software by © MyBB