I am using colorbox node module on my site, and it looks like the ajax callbacks for rendering the node are not cached at all. Tested it with a simple snippet in the node template:

<div>generated on <?php $dt=new DateTime();print $dt->format('d.m.Y H:i:s');?></div>

Colorbox is using a custom display, to have a custom node.tpl

function mytheme_preprocess_node(&$vars) {
  if ($vars['node']->type == 'my_content_type' && $vars['view_mode'] == 'colorbox') {
    $vars['theme_hook_suggestions'][] = 'node__my_content_type__colorbox';

Caching for anonymous user is turned on and works for node pages.

is this issue related to colorbox node (e.g. missing caching implementation in colorbox node) or some other module?

I dived into the code of colorbox node and found out that the click on a colorbox link will be rewritten and rerouted through this menu:

 * Implements hook_menu().
function colorbox_node_menu() {
  $items['colorbox/%colorbox_node_url'] = array(
    'page callback' => 'colorbox_node_output',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'load arguments' => array('%map'),
    'delivery callback' => 'ajax_deliver',
    'theme callback' => 'ajax_base_page_theme',
    'type' => MENU_CALLBACK,
  return $items;

is there a way to cache 'delivery callback' => 'ajax_deliver', without hacking the colorbox_node_output() function? Whats the best practice here to get this into caching? I think implementing a cache inside colorbox_node_output() might already be too late because it is running through the complete bootstrap process before executing that function.

1 Answer 1


This can be done. Will require 2 hooks hook_menu_alter() & hook_boot() and some non trivial code.

Top level overview of how to do this:
Use hook_menu_alter() to call a wrapper around colorbox_node_output() that will cache its output. Use hook_boot() to check the cache and deliver the cached content, routing the cached content though ajax_deliver().

An example of cache code flow can be seen in the 6.x-2.x ESI module. esi_get_page_cache() gets called from esi_boot. esi_set_page_cache() is what sets the cache; you can see it getting called at the bottom of these functions: esi__block_handler() & esi__panel_pane_handler(). Side note: A big reason the ESI module's cache code has a lot of complexity is it's compatible with D6 core and Pressflow; both have different code for the page cache.

  • thanks for the input. I already looked deeply into it. and tried/ glued it together with drupal.org/project/js but, now one of the main problems here: ajax_deliver needs for whatever reasons a full bootstrap. I will answer this question with the total results of my research as soon as Ive completed it. Mar 16, 2013 at 20:07
  • I would have guessed otherwise given the comments in the code for ajax_footer. In that case do everything that ajax_deliver does, expect for ajax_footer and cache that.
    – mikeytown2
    Mar 16, 2013 at 20:18
  • thats the plan :) got it on my road map, but the solution isnt that trivial, there's pretty much data exchange within ajax_deliver and drupal's core like session stuff. I have to find out whats important for colorbox in that case. I will post an answer as soon as I had time for that. Mar 17, 2013 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.