SLB: Compatibility with Caching Plugins

By Sol in Lab

Julio recently pointed out that Simple Lightbox was not working when W3 Total Cache was activated.  After some digging, it turns out that when the CDN functionality of W3TC is enabled, there are some scenarios where SLB will not be able to load an image.

Just the Facts

  • W3TC uses output buffering to process a page before it is displayed in the user’s browser.
    • If the CDN functionality is enabled, then it uses regular expressions to find/replace all URIs that are enclosed in quotes.
  • SLB works with attachment links by retrieving the attachment image source URI at runtime & adds it to the rel attribute of the link
    • Example: rel="slb_source[image_uri.jpg]"

Scenarios

The only scenario where there will be an issue is when W3TC’s CDN functionality is enabled and attachment links are used when inserting images/galleries into a post.  Default links that point directly to image files are unaffected and continue to work properly.

A Quick (and Dirty) Solution

Since W3TC’s regular expressions work on URLs enclosed in quotes, a quick and dirty solution is to simply add single quotes to the image source value in the rel attribute:

rel="slb_source['image_url.jpg']"

This has been tested and allows the SLB to work with the updated image URIs pointing to the CDN.

Pros

  • Consistent: Source URI in rel attribute is processed like all other internal URIs in post output
  • Automatic: No change unless W3TC output buffering is executed

Cons

  • Dependent on being compatible with W3TC regular expressions
    • If W3TC’s code changes, SLB compatibility may break

Questions

  • Problems with single quotes in rel attribute?

I’m not a fan of functional code that is dependent on external code, but if adding single quotes do no harm and provide compatibility with W3TC, then this may very well be the solution I will implement.  After a bit of testing, it will probably be released in SLB 1.5.6b2 in the next couple days.