Lessons learned about JSON/JSONP in Jquery and CORS and Akamai

At work, we needed to change a JSONP ajax call to JSON in order to implement correct cache-headers for optimizing the load behaviour of the shop.

To accomplish this, we needed CORS enabled headers on the server side. Implementation is easy, thanks to NelmioCorsBundle in symfony.

Adding “Cache-Control” headers is also easy, one-liner ;)

But then 3 subtle problems needed to be solved until code worked on production:

  • CORS implements a OPTIONS call, this is by default disabled in Akamai :(
  • Cache-Control header were overwritten due to Akamai :(
  • Jquery was the best..its not enough to specify the datatype “json” instead of “jsonp”, no you need “crossDomain” also set to false that Jquery actually uses JSON! Unexpected bevaviour. Like. Not.

The JSON call was needed to send correct cache-headers, it works like a charm after Jquery was forced to ;) For Akamai you need just patience, 40-50 minutes for reconfigure on live. Staging Akamai is with 10 minutes much faster..

So a one liner can actually need a long time to go in production.