Caching can deliver wrong dark/light mode
SamuelmdLow opened this issue · 8 comments
I'm not yet sure how to fix it. Is it http headers? Maybe!
cause I think the site may be cached as light mode everytime and then change to darkmode when a darkmode user loads it
I definitely see the issue on different web browsers on my mobile. I tried on Google and Bing to be specific.
Inline advertisements do not show correctly as mobile or desktop because caching just returns whatever format was cached. This means ads can show as way to wide for a mobile device
I think this might help coderedcorp/wagtail-cache#17
I think we have to add WAGTAIL_CACHE_IGNORE_COOKIES=False
into base.py
but I can't seem to run the site with DEBUG=False
to test the caching
I've moved the ad problem into this issue because I think the solution should be to change it so that the template does not differ from mobile to desktop - rather than to change how caching works between mobile and desktop
I've confirmed that the site does not "flash" to dark mode when WAGTAIL_CACHE_IGNORE_COOKIES
is set to False
.
Wagtail Cache is stripping cookies to stop 3rd-party tracking cookies from making pages un-cacheable. Django never sees the lightMode
cookie because we set it with JavaScript on the client and therefore Wagtail Cache can't distinguish it from a 3rd-party cookie.
While disabling cookie stripping does fix the dark mode issue, unfortunately it makes the cache pretty useless. A common alternative solution is to disable caching on pages that have personalization features like this, but unfortunately that approach would disable caching for the entire site, since dark mode is a setting on every page.
This is a tricky one! I'll let you know if I think of any fixes. That last issue you linked to looks promising.
Turns out you can just decide it client side before the page renders. Our script was just waiting till the whole page rendered before running. Changed that and also made it go back to using local storage since everything is client side now.