How to detect prefers-color-scheme change in javascript?

You can add an event-listener with callback on the MediaQueryList returned by Window.matchMedia(): function activateDarkMode() { // set style to dark } // MediaQueryList const darkModePreference = window.matchMedia(“(prefers-color-scheme: dark)”); // recommended method for newer browsers: specify event-type as first argument darkModePreference.addEventListener(“change”, e => e.matches && activateDarkMode()); // deprecated method for backward compatibility darkModePreference.addListener(e => e.matches … Read more

Where to store a JWT token properly and safely in a web based application?

Where to Store Your JWTs With token-based authentication, you are given the choice of where to store the JWT. We strongly recommend that you store your tokens in local storage/session storage or a cookie. Web Storage (local storage/session storage) Commonly, the JWT is placed in the browsers local storage and this works well for most … Read more

How can I determine a user’s locale within the browser?

The proper way is to look at the HTTP Accept-Language header sent to the server. This contains the ordered, weighted list of languages the user has configured their browser to prefer. Unfortunately this header is not available for reading inside JavaScript; all you get is navigator.language, which tells you what localised version of the web … Read more