You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately the Accept header isn't a great one to vary on as there is too much difference between different browsers, and even browser versions. For example for this issue page on GitHub in Chrome I get:
This kind of variance will kill cache efficiency, so blindly varying on this header is not a great idea.
What you can do for ActivityPub is normalize and filter the header, and set a specific variant flag with a custom cache config. For example:
// Do some string manipulation with $_SERVER['HTTP_ACCEPT']
$config['variants']['activity-pub'] = $result_from_manipulation;
return $config;
I know some users do this to detect requests from smartphones based on the User-Agent header, which is also not a great one to vary on, without converting it to a less variable 1/0 or mobile/desktop value.
Thanks for the quick feedback. I was aware of the custom configuration file but wasn't sure if variants is what I was looking for. I'll give this a try!
Activity
kovshenin commentedon Mar 13, 2023
Hi @ocean90, thanks for your comment!
Unfortunately the
Acceptheader isn't a great one to vary on as there is too much difference between different browsers, and even browser versions. For example for this issue page on GitHub in Chrome I get:And in Safari I get:
This kind of variance will kill cache efficiency, so blindly varying on this header is not a great idea.
What you can do for ActivityPub is normalize and filter the header, and set a specific variant flag with a custom cache config. For example:
I know some users do this to detect requests from smartphones based on the
User-Agentheader, which is also not a great one to vary on, without converting it to a less variable 1/0 or mobile/desktop value.If you're looking for more information about custom cache configuration, my friend @roytanck published a post a while ago: https://roytanck.com/2022/01/13/tweaking-surge-by-adding-a-configuration-file/
Hope that helps!
ocean90 commentedon Mar 13, 2023
Thanks for the quick feedback. I was aware of the custom configuration file but wasn't sure if
variantsis what I was looking for. I'll give this a try!ocean90 commentedon Mar 14, 2023
Got it working with the following config for
variants:Thanks again!
kovshenin commentedon Mar 15, 2023
Nice, thanks for sharing @ocean90! Also IIRC you have to return
$configas it's passed on to a variable which is then merged with the main config:surge/include/common.php
Lines 53 to 56 in b0f2a2d
ocean90 commentedon Mar 15, 2023
Right, I already had that in my config. Updated above in case anyone wants to copy it as is.