I'm trying to create a block, which shouldn't get cached, even for anonymous users. But there's "Normal" page caching enabled on the website. As I've read in various places, the BLOCK_NO_CACHE setting doesn't really count for anonymous users when page caching is enabled.

As it stands, it's not an option for me to turn off the page caching, as the website receives moderately high traffic.

I've first tried injecting some HTML with hook_footer but this function doesn't get called as well when page caching is enabled.

The block I'm trying to implement is a very simple one, it only has a bit of text and a link, which upon clicking, sets a cookie on the user's browser (with PHP), and returns the user back to the page where they clicked the link on. Upon returning to the page, the block needs to attempt to read the cookie, and if the cookie is set, the block should no longer be displayed.

However with page caching turned on, if AnonymousUser-A clicks the link and no longer sees the block, then AnonymousUser-B comes to the site, they also don't see the block.

Is there a workaround I can use to get around this issue? As you can see from my use of hook_footer, I'm not heavily inclined to implement this as a block. Any solution that will fit the above purpose is welcome.

  • 1
    Have you come across hook_boot()? It gets run for all pages, even those that are cached
    – Clive
    Jun 28, 2012 at 11:36
  • Thanks, and sorry to be a pain, but could you write me a small example on how to use hook_boot() to inject some HTML on the current page?
    – Beebee
    Jun 28, 2012 at 15:16
  • You can't use hook_boot to inject HTML on the current page... at least not in a sane way.
    – mikeytown2
    Jun 29, 2012 at 0:32

2 Answers 2


Ajax Blocks or Ajaxify Regions (since you're in D6) allow dynamic blocks within cached pages.

  • I'm afraid it's not what I'm looking for, as I'm particularly having issues with anonymous users because BLOCK_NO_CACHE is intended to work for authenticated users, but not for anonymous with full page cache on.
    – Beebee
    Jun 28, 2012 at 15:15
  • Trust me when I say that one of the 3 modules above will fix your issue.
    – mikeytown2
    Jun 29, 2012 at 0:28

If you want a different example, you can use javascript to read a cookie and hide that blocks div based off of a cookies value. Have the block always be show at the PHP level and use JS to hide it client side.

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.