7.x-2.x

This module has undergone a complete rewrite for security reasons. Please test the latest 7.x-2.0-betaX release below. Modules that already have integration with the 7.x-1.x API, you will need to re-integrate your callback to provide a token at the very least. There is currently no "upgrade" path. If you have questions, find a bug or have a feature request please file an issue.

Overview

JavaScript callback handler is an interim solution for high-performance server requests including (but not limited to) AHAH, AJAX, JSON, XML, etc.

This project targets module developers and provides a "bare bone" callback handler which is intended to be addressed by modules wanting to improve response times for specialized tasks.

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 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: Change API implementation for 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

Credits

Authors of the 7.x branch and maintainers as of 6.x-1.0:

Authors of the pre-6.x-1.0 releases:

This project has been sponsored by:

SYNETIC
Full service Drupal specialist. From custom made webapplications to content management systems, intranet and e-commerce shops.
UNLEASHED MIND
Specialized in consulting and development of Drupal powered sites, our services include installation, development, theming, customization, and hosting to get you started.

Project Information

Downloads