ubyssey.ca icon indicating copy to clipboard operation
ubyssey.ca copied to clipboard

Caching can deliver wrong dark/light mode

Open SamuelmdLow opened this issue 1 year ago • 7 comments

I'm not yet sure how to fix it. Is it http headers? Maybe!

SamuelmdLow avatar Feb 02 '24 23:02 SamuelmdLow

cause I think the site may be cached as light mode everytime and then change to darkmode when a darkmode user loads it

SamuelmdLow avatar Feb 02 '24 23:02 SamuelmdLow

I definitely see the issue on different web browsers on my mobile. I tried on Google and Bing to be specific.

Nishim12 avatar Feb 05 '24 05:02 Nishim12

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

SamuelmdLow avatar Feb 06 '24 10:02 SamuelmdLow

I think this might help https://github.com/coderedcorp/wagtail-cache/issues/17

SamuelmdLow avatar Feb 08 '24 23:02 SamuelmdLow

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

https://docs.coderedcorp.com/wagtail-cache/getting_started/django_settings.html#wagtail-cache-ignore-cookies

SamuelmdLow avatar Feb 12 '24 03:02 SamuelmdLow

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

SamuelmdLow avatar Feb 12 '24 03:02 SamuelmdLow

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.

psiemens avatar Feb 13 '24 21:02 psiemens

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.

SamuelmdLow avatar May 23 '24 05:05 SamuelmdLow