How do I return JSON data compatible with the Boost module? In a custom module a, I return a JSON string that needs to be compatible with the Boost module.

My first try was using the following code:

if ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) &amp;&amp; 'XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH']) || strpos($_SERVER['REQUEST_URI'], '?json') !== FALSE) {
  header('Cache-Control: no-cache, must-revalidate');
  header('Content-type: application/json', true);
  $json = loadData();
  die(json_encode($json));
}


This is obviously that this output won't be cached. Than I replaced the line with die() with the following one:

return drupal_json_output(($json));


This works, but it is not cached. I enabled the JSON output in Boost, but nothing happens.

What should I try?



Removing the two header lines does not change anything. The function drupal_json_output adds the Content-Type: application/json. But I belive that boost only accepts text/javascript. Also if I override the Content-Type again nothing will be cached.
Why do you need to cache JSON output? Anyhow, try removing header('Cache-Control: no-cache, must-revalidate'); and see what happens.