Some blocks / views attach CSS/JS conditionally, i.e. only if the viewed content requires it. For example in the commerce cart view, the CSS file commerce_cart.theme.css is only loaded when the cart actually has any content (see commerce_cart_preprocess_views_view).

The problem is when the CSS/JS was not attached while a page was saved to the cache. On a subsequent request a personalized block / view may have other content requiring the style/scripts. However these assets will not be available on the cached page and therefore the personalized fragment might not look good / work properly.


znerol’s picture

Issue summary: View changes
Status: Active » Fixed
Related issues: +#2146917: Always add commerce_cart.theme.css even when the cart is empty

The cart is actually a special case and therefore I think it should be solved over at commerce: #2146917: Always add commerce_cart.theme.css even when the cart is empty.

Nevertheless we now have predictable fragment ids for blocks. Therefore it is easy to inject the css whenever an Ajax/ESI tag for the commerce cart block is about to be rendered by implementing a preprocess function:

 * Implements hook_preprocess_HOOK().
 * Enforce that commerce_cart.theme.css is added when rendering the cart block.
function YOURTHEME_preprocess_authcache_p13n_fragment(&$variables) {
  if ($variables['fragment'] == 'block/commerce_cart-cart') {
    drupal_add_css(drupal_get_path('module', 'commerce_cart') . '/theme/commerce_cart.theme.css');

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.