Header items added from blocks get removed when page cache regenerates

I have a block that adds a couple of header items in the view() routine using addHeaderItem. Block caching is enabled, as well as full page caching.

The first time the cache generates, everything works as intended. However, when the page cache expires, it regenerates the page cache, but simply re-uses the cached block output. This means the addHeaderItem calls no longer get called, and the items get removed from the header.

How would you all advise I solve this?

Thank you!

That is a typical cache issue. The easiest solution is to add the header items from the block controller. Usually in the registerViewAssets() method.

If on v9 and the assets are in a ‘feature’, you could also re-work the block controller to make use of the features mechanism (there is a fair bit of features if you look back through forum threads)

1 Like