| | | |

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

  • |

    Having Your Bowels Cut Your Run Short

    Yeah, it’s not pleasant to talk about, but as a runner you generally are aware of the things that can happen while on a long run. And when you aren’t someplace where you can find a well placed #JohnnyBlue things get interesting real quick. I had to cut a couple of miles off my long…
  • |

    Intense Monday Recovery Run

    Give just $25, and it’ll be $50 with the current matching. $25 a day until the #GRMarathon to hit $1000. https://timn.me/2Kx7NEr #HWI #Run4Water #WhyIRun Every morning I get ready to go run I turn to the sink to fill up my water. However much I feel like I need or want. For villages in Africa…
  • |

    Putting In Some Miles On A Crisp Tuesday Morning

    This morning I opted to run without the cleats, since I could see that the sidewalks looked to be mostly cleared. Unless there is snow covering the sidewalks the cleats just don’t feel very comfortable to run in. It was a nice easy run, listening to some worship workout music: Christian Workout – 50 Best…
  • |

    Keeping The Trots At Bay

    This morning the wheels pretty much fell off my 6.5 mile run. As you can see I really only got a little more than 4 miles in. I had to stop because I just couldn’t keep jostling things around and keep the trots from hitting me. I did manage to get another really slow 1.5…
  • |

    A Little Later Thursday 3 Mile Run

    Getting in my 3 miles before we head out for another week of camping. Even though I got out later than normal it was still surprisingly not too hot. Next few runs will be in the Wisconsin Dells. #HWI #KCC #Run4Water #WhyIRun #GRHalfMarathon #RiverBankRun

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.)