What's the fastest method/implementation for an Ajax callback? I have a map which loads markers via ajax on various/numerous map events. Currently, I define a custom page callback for my hook_menu() item which prints my json/js.

Since my page callback does not return any content and only prints content, Drupal does not render the full template, menu, etc, and thus allows me to return a page with only my JavaScript.

Although this does work, I believe that Drupal still fully bootstrapping, which means it is adding a lot of overhead I would like to drop.

I've been looking at High-performance JavaScript callback handler, which boasts itself as a "High-performance JavaScript callback handler" and which, in short, looks as though it offers a js.php to compliment index.php to direct your requests to and customize/limit/optimize the bootstrapping Drupal does by default.

Unfortunately the js project doesn't have a D7 release yet (petition for one here), which leads us to the beginning...

What is the fastest way to implement an Ajax callback in Drupal?
I define a custom page callback for my hook_menu() item which prints my json/js.


That is what Drupal 6 offered. The Drupal 7 AJAX framework can do a little more than that. Yes it bootstraps Drupal, but it also gives a lot of features for free. In short you can use ajax_deliver() as a page delivery method, and send commands to the browser.


  ... Ajax may be enabled by adding classes to buttons and links. By adding the 'use-ajax' class to a link, the link will be loaded via an Ajax call. When using this method, the href of the link can contain '/nojs/' as part of the path. When the Ajax framework makes the request, it will convert this to '/ajax/'. The server is then able to easily tell if this request was made through an actual Ajax request or in a degraded state, and respond appropriately.


However if you want to sidestep the framework for performance reasons then there is nothing to stop you calling php files in your module directly from javascript. You will get no Drupal goodness but you also will have complete control over the page.