JS Callback Handler

Component ID

251622

Component name

JS Callback Handler

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

203596

Component created

Component changed

Component body

Overview

JS Callback Handler is a solution for creating highly performant server requests. This includes, but is not limited to, creating simple JSON callbacks.

This API is intended for module developers who wish to provide more of a "lean" approach to the Drupal bootstrapping process (not the front-end framework).

Note: this API does nothing by itself. It requires other modules to leverage its functionality and APIs.

Background and purpose

Drupal handles all requests - except those for public files - involving a standardized and complex bootstrap and database logic. Although that makes sense in most classic REST requests and is highly recommended for standard tasks due to caching and security reasons, it may cause a lot of performance cost on well frequented sites with much AJAX functionality.

JS (Callback Handler) does not really do anything itself but instead provides an API to other developers who want to improve their project's AJAX (, SOAP, AHAH, JSON etc) performance. This is mainly achieved with bypassing a lot of Drupal core functions which are not needed in every case, and by allowing to determine which core functionality will be loaded on a per-request base.

Example

Think of a module which is only used for signaling that a user is still on your site. You might want to implement a JS interval who frequently tells the server "hi, this is session X with session cookie Y telling you that I'm still alive". You would not need any localization, forms API or theme engine involved to handle such a request properly, but think of the server load such a function would cause with some 100 users hailing every, say, 10 seconds using a complete Drupal request.

Apache benchmarks

index.php:

  ab -n20 -c1 http://example.com/index.php?q=js/mymodule/callback
  Requests per second: 2.24 [#/sec] (mean)
  Time per request:    446.846 [ms] (mean)

js.php:

  ab -n20 -c1 http://example.com/js.php?q=js/mymodule/callback
  Requests per second: 16.84 [#/sec] (mean)
  Time per request:    59.371 [ms] (mean)

Requirements

  • Your server must support URL rewrites. E.g. in Apache, you need mod_rewrite enabled.
  • Clean URLs need to be activated in your Drupal setup.

Integration

Contributed (third-party) modules that support the high-performance JavaScript/AJAX callback handler:

Project 7.x-1.x 7.x-2.x
Administration menu #1981308: Call to undefined function field_info_fields() in admin_menu.map.inc on line 111 #2219467: Fix client side caching (including js_7.x-2.x)
Barracuda ✔︎ GH Issue #586
Chatblock ✔︎ #2417411: js module integration
IP Geolocation Views & Maps ✔︎ #2417415: js module integration
SHS ✔︎ #2417417: JS 7.x-2.x Integration

Blog posts

You can find an excellent post about the JS module (with an example) by another Drupal enthusiast here:
http://www.pixelite.co.nz/article/high-performance-ajax-callbacks-drupal-7-and-js-module