MapofLife / MOL

Integrating information about species distributions in an effort to support global understanding of the world's biodiversity.
http://mol.org
BSD 3-Clause "New" or "Revised" License
26 stars 2 forks source link

Jquery JSONP requests are not getting cached by CloudFront #183

Open jmalczyk opened 11 years ago

jmalczyk commented 11 years ago

A JSON-P request issued by jQuery assigns a callback=somerandomnumber parameter, so as not to conflict with other calls that could potentially be happening at the same time. Unfortunately this means a sql result is never cached. Fortunately the same problem does not exist for tiles, image sources can be assigned cross-domain.

The solution is to explicitly set a callback function name instead of letting jquery assign one when making sql api requests. Make sure to pick something unique to the sql request, like ac{term} for an autocomplete request for {term}.

$.getJSON(
   "http://blahblahblah.cloudfront.com/api/v2/sql?" +
      "q=select n, v from ac where n~*'\\mPum' or v~*'\\mPum'&callback=acPum",
   function(response) {
       self.handleAutocomplete(response);
   }
);