The js/css doesn't get placed on the page for cached blocks. I know this is a very common issue across all drupal modules but there should be a solution.

Would a solution be to add in the JS in a block_view_alter hook?

Comments

Status:Active» Postponed (maintainer needs more info)

Hmm, you could always include the library manually with drupal_add_library in your template.php file. Either in template_preprocess_html or template_preprocess_page

So when you enable the cache in views FlexSlider blocks stop working? Or when you enable the block cache in the Config/Performance page?

Yep, that would be one way to do it. Basically whenever you do something in a theme() function, I think the intention is (or, was) to only affect markup of the item being themed. So alterations made to the page js/css during theming aren't cached properly.

Yes, so what we found was the first time a user viewed a page, the flexslider block worked. Then when the user revisited the page (not a cache anonymous page, but a page where the block response was cached), the html for the flexslider was found but the JS didn't get loaded.

Since the functionality of block caching is to always call hook block alter regardless of caching, I think a pretty clean solution would be to also add JS in there so a cached block will still work.

That makes sense to me. The only issue though is determining the id of the blocks with FlexSlider in them from views so we can perform the alter properly. Any ideas on that?

Title:Flexslider blocks can't be cachedFlexslider library should be #attached to content to allow caching
Component:Views Style Plugin» Code
Category:bug» task
Status:Postponed (maintainer needs more info)» Active

Flex Slider currently uses calls libraries_load() to load the required CSS/JS (which is incompatible with caching). The library should use #attach to attach itself to fields/views/blocks etc.

For example:

<?php
'#attached' => array(
 
'libraries_load' => array(
    array(
'flexslider'),
  ),
),
?>

Status:Active» Postponed

Attaching the Flexslider library to the field formatter is straightforward but I've run into a wall when it comes to attaching the library to the view style plugin.

See #1894736: Cannot use #attached to add general CSS/JS/Library to a View for the issue and #1811828: Use #attached to find the css/js of a view for the change that went into Views for D8 core.

I'm marking this postponed unless someone has a solution. :)

Want to post your patch thus far? Or I can create a branch specific to this task.

+1. We are getting similar symptoms with caching + views + FlexSlider. I'll double check on our sites, but I'm pretty sure it happens if you use either the View Format of "FlexSlider" or the Views Slideshow with the Slideshow Type = FlexSlider. We noticed this heavily using the two FlexSliders on the page for a Slide and Carousel of thumbnails for navigation.

We also are using a full cache stack: views cache, Drupal page cache, Advanced Aggregation for CSS / JS aggregation, Redis, APC, and Varnish. I'll be happy to test if a patch is up!

Component:Code» Views Style Plugin

So for fields this should be working. However with Views it seems to be an issue with Views itself. Not much for us to do except link out to the work arounds.