I use a cookie to control whether a light or dark theme is used for my website:
- If no cookie is set, my website respects the user’s system preference
- If the
themecookie set todark, it uses the dark theme - If the
themecookie set tolight, it uses the light theme
(It does so by adding a class to the <html> tag.)
I am using the regular Kirby page cache.
I found out that Kirby is pretty smart when handling caching and cookies. (But only if I use Kirby’s functions to set/get cookies, eg. Cookie::set().)
Now, when the cookie is not set, Kirby will cache the page normally. If the cookie is there, Kirby will not cache the page, as is expected.
How can I get Kirby to cache the two additional versions for the light and dark theme and then serve those, whenever a user has set the cookie to the respective value?
Please note, that I do not want to use JavaScript to apply the theme after the page has been loaded.
Any pointers would be much appreciated!