| | | |

Fixing OpenLiteSpeed Caching for ActivityPub on WordPress

black laptop computer turned on showing computer codes

I have been using the plugin for for many years, I’ve also been using the web server for probably just as long(or more). In all that time I wasn’t actually aware that my site had a major caching issue, mostly because I wasn’t really pushing my WordPress site as something to directly interact with on the . I was still manually posting to my account with a link to my website.

Some Backstory

Since last fall when the Twitter apocalypse started to happen, and the rush on new users to the Fediverse, I started using my WordPress site as more of a first stop participant on the Fediverse. I follow my website on Mastodon and boost my website posts. As I started doing this, and as others have also started to think about using the ActivityPub plugin on their own WordPress sites, I became aware of a major issue with the caching on my site where sometimes Fediverse users were getting straight HTML and sometimes my website visitors were getting .

After some conversation with others on Mastodon about other caching issues with ActivityPub & WordPress it was revealed that it came down to the Accept headers being received by requests to the caching services. The caching services could be things like or web servers such as OpenLiteSpeed, or even WordPress caching plugins. In my case I use the OpenLiteSpeed web server caching and I started digging into how caching works in OpenLiteSpeed and how I could fix it for my WordPress site.

The Research, Debugging, and Testing

My research initially took me to some details in the OpenLiteSpeed documentation about the possibility of setting up difference caches for mobile versus desktop.

There was also some documentation related to creating different caches based on geographic locations.

The commercial LiteSpeed Enterprise documentation goes into much more detail about the use of Vary cache keys. And this further pointed me in the right direction. I went down the road of starting to write some Rewrite rules and testing them with PostMan & curl to check the responses. There were a couple of times that I thought I had things finally working, and even shared them in some various places. However, once again someone pointed out to me that my website was serving up JSON to website visitors. Back to more debugging. This time I used my Mastodon instance and the post/user search functionality to send the requests and I turned on high levels of logging in OpenLiteSpeed and finally found that the Accept headers being sent from Mastodon were a bit more broad than my Rewrite rules were accounting for. I didn’t get the full headers I found saved here and they have now been cleared so I can’t provide the actual findings. Things seem to be working now with the fix outlined below.

OpenLiteSpeed Fix Using a Rewrite Rule

The fix that ultimately worked in my testing was a pretty simple Rewrite rule in my site’s root .htaccess file.

#BEGIN ActivityPub Cache Handling
<IfModule LiteSpeed>
RewriteEngine On
CacheLookup on
RewriteCond %{HTTP_ACCEPT} application\/((activity|ld)\+json|json|ld\+json.*profile.*activitystreams")  
RewriteRule .* – [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+activitypub]
</IfModule>
#END ActivityPub Cache Handling

Similar Posts

  • |

    Taking On The Wet And Windy Tuesday Run

    It was a kind of interesting morning, weather wise. There was some big thunder before 4am but when I got outside for my morning run there wasn’t much for rain, just some sprinkles and mist off-and-on. The wind came and went as well. The crazy thing once again is to see my pace improve of…
  • |

    Changing Focus And Changing Pace

    I expected to have a better overall average time given my training plan had me doing high intensity sprints. It’s OK though as my times were faster than my plan actually called for. The 2nd half of my run was really a little bit of a wake up call on where my focus has been…
  • |

    Still Running, Starting A New Plan

    I have still been running but just haven’t taken the time to post about them. I ran 13.1 miles last Saturday and around 7 Miles on Tuesday, I did take a break Monday in order to get some extra sleep after a late night. This morning I had another interval training run this morning that…
  • |

    More Miles For Clean Water

    During this season of celebrating Christ’s birth we can celebrate 15 new wells that will be going in this coming year. There’s more work to be done, so consider a year-end gift to clean water. #HWI #Run4Water #WhyIRun #GRGus Give the blessing of clean water: https://timn.me/2Kx7NEr

One Comment

  1. @timnolte this shows up perfectly for me in mastodon!Hopefully this comment appears back on your WP!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)