In 1.x-dev lazy loading adds an almost empty div with "Loading..." and adds JS separately. Somehow that doesn't work well with anonymous page caching (or block caching?), because the empty block is cached, but not the required JS.

Wrong:

$lazy_load = '<div class="throbber twitter-pull-lazy" id="' . $id . '">' . t('Loading...') . '</div>';
drupal_add_js('jQuery(document).ready(function () { jQuery.get("' . $uri . '", function(data) { jQuery("#'. $id . '").html(data).removeClass("throbber"); }); });', 'inline');

Right:

$script = 'jQuery(document).ready(function () { jQuery.get("' . $uri . '", function(data) { jQuery("#'. $id . '").html(data).removeClass("throbber"); }); });';
$lazy_load = '<div class="throbber twitter-pull-lazy" id="' . $id . '">' . t('Loading...') . '<script>' . $script . '</script></div>';

That way the inline JS is cached together with the empty block. Separation of markup and code isn't always good.

I've no idea how this works in 2.x, so I might be waking up dead cows (or whatever, you know).

Comments

rudiedirkx’s picture

Issue summary: View changes