0

Possible Duplicate:
Is it possible to force jQuery to make AJAX calls for URLs with gzip/deflate enabled?

I'm going across two different domains with jsonp. Domain1 asks Domain2 for some json data using $.getJSON with a callback parameter and that works great, no problems there.

Domain2 can also serve the json data gzipped.

I'd like to utilize this feature but I don't know how to request it from Domain1 using jQuery's $.getJSON.

Is this possible and if so can you please give me an example (or any other workaround).

Thanks!

Community
  • 1
  • 1
Nik
  • 7,086
  • 6
  • 36
  • 52
  • 1
    Normally this would be handled by the browser, transparently, if you have an `Accept` header that specifies zip. – Dave Newton May 14 '12 at 20:59
  • @Dave-Newton How would I add the header to the call? – Nik May 14 '12 at 21:09
  • @PedroFerreira not sure if it is or not, the cross domain is a part of my issue that i was hoping someone would be able to explain. From what I understand an ajax call and a jsonp call are not entirely the same. – Nik May 14 '12 at 21:23
  • @user1394625 then it's even worse... a JSONP request is just another ` – ubik May 14 '12 at 21:29

2 Answers2

1

gzipping your http traffic is a server option that is transparent to the actual processes that work with the content (your script in your case). The browser takes care of the gzipping, but it will only work if both sides of the connection support it (this is communicated in the request header). Also you must enable it server side (for instance use mod_deflate in apache)

You state that the server on domain2 supports gzipping, so if you configured it correctly all traffic that is "gzippable" will get gzipped automatically. No extra work on your part is necessary.

If you want to know if yrou traffic gets gzipped take a look at the response headers of your jsonp call. They should say that gzip is used. You can do this in chrome for instance.

Koen Peters
  • 12,798
  • 6
  • 36
  • 59
  • Thanks, you are right. I was checking the size of the response after the browser had already handled the gzipped data. After checking the response headers it clearly shows that it was gzipped and that it was much smaller. I just didn't look carefully enough...my bad. – Nik May 14 '12 at 21:50
  • OK, no problem. Good that you figured it out. – Koen Peters May 14 '12 at 21:51
0

I don't think there is a way to tell your browser what to do in this case. If this is a JSONP request we are talking about, then it is up to your browser deciding which headers get sent. A JSONP request is just another <script> tag.

ubik
  • 4,440
  • 2
  • 23
  • 29