Support » Plugin: Surge » Adding a dark theme on sites using Surge

  • Resolved iamonlythird

    (@iamonlythird)


    Super promising plugin. If we were to add a dark theme to the site, I presume we’ll store it via a cookie, which will break the caching? Unless if fragmented caching is possible via Surge?

    In other words, what’s your suggested technical route of adding a dark theme (for logged out users) on sites that uses Surge?

    Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Konstantin Kovshenin

    (@kovshenin)

    Thanks! Cookies will automatically fragment your cache. As long as you’re not serving a Set-Cookie header on every request, it will work.

    If the dark-theme implementation is fully JavaScript0-based, then you can also prefix your cookie with an _underscore and Surge will ignore it completely, and remove it from the $_COOKIE global as well.

    Hope that helps!

    Thread Starter iamonlythird

    (@iamonlythird)

    Thanks. So I can simply set the javascript cookie as followed:

    document.cookie = "_prefix_mode=dark; max-age=129600; path=/;";

    And it will work with Surge.

    Plugin Author Konstantin Kovshenin

    (@kovshenin)

    Correct.

    Thread Starter iamonlythird

    (@iamonlythird)

    @kovshenin

    Testing this now as we speak, so a follow-up question.

    If the cookie is present, will it still display the cached version of the page? So for example, if I load up the page (as a guest), and custom cookie named ‘_hello’ exists, will it display the non-cached version of the page?

    Thanks!

    Plugin Author Konstantin Kovshenin

    (@kovshenin)

    Yeah, any cookie with an underscore is skipped by default, treated as a js-only cookie. So a request with _hello will get a cached response (if one exists). You can look at the X-Cache header in your dev tools and see whether you get cache hit or miss.

    Hope that helps.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.