0

Scenario: I have content type with a field 'images' (Widget: plupload). View created and displayed on Home page. View has Formatter: LightBox2, LightBoxType: Single Lightbox, Image-Style: thumbnail image-style for the images. Whenever user click on image, LightBox2 shows original image.

Problem: Everything working fine. But the images are getting cached in browser cache. Hence I followed https://www.drupal.org/node/2313539 Cache Busting discussion and changed theme.inc theme_image() function. Now the thumbnails have time(cache busting string) in their name but lightbox still the same. I get the point that i have write or hook the formatter as well to make it work in views. Not sure where and what should change in LightBox module or elsewhere.

This is what HTML looks like on page

<a href="sites/default/files/images/3.jpg" rel="lightbox[field_images][<p><a href="sites/default/files/images/3.jpg" title="Download Original" download="">Download Original</a></p>]" title="" class="lightbox-processed">***<img typeof="foaf:Image" src="sites/default/files/styles/app-thumbs/public/images/3.jpg?itok=-OKZ8zZW&hash=2563415" width="200" height="200" alt=""></a>

where <img> tag has src url appended with '&hash=2563415' i.e. cachebust string, but anchor-element doesn't have the same. Any ideas how to make Lightbox2 anchor element to include cachebust string element as well. Drupal version:7.41, LightBox2

  • What is the problem with browser caching? Why do you want to prevent it? – Neograph734 Feb 12 '17 at 15:40
  • Actually the images are updated every half an hour, and the display-view shows the recent ones. Browser cache hindering with this function of website (by showing the cached images). Hence I need cache bust string so that browser always displays the most recent images. I have kept the names of images same and background script changes the actual image files and regenrates Image style. – u tyagi Feb 12 '17 at 16:03
0

OK, I solved it. Cachebuster can be implemented as discussed in shared url for drupal 7 by editing includes/theme.inc, and theme_image function. Just add attributes['src']with a random string say time(). Further, lightbox2 module can be tweaked to append random string in a href, by editing lightbox2/js/lightbox.js, just edit start: function(imageLink, slideshow, lightframe, lightvideo, lightmodal) {} and append anchor.href with new Date().getTime().

These two tweaks will make sure that drupal is giving img src appended with time and lightbox2 inserting time() in anchor href. Browser will never cache these images.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.