I am trying to add themes dynamically to a site.
For testing purpose I store the theme value in localStore.theme
and set the theme in the body tag
It seems to work, but for a few milliseconds the theme is gone and “flicker”
The theme is set on load
“`
window.onload = function() {
alert(localStorage.theme) /* to show the flicker */
document.body.dataset.theme = localStorage.theme
/* if no theme reset to classic*/
if (localStorage.theme === null) {
window.localStorage.setItem(‘theme’, “classic”);
}
}
—–> Live:
I have tried to move the theme to the html tag, but I cannot figure out how do this dynamically:
`<html data-theme=”classic” lang=”en”>
My question is how to avoid the flickering during reload of the page?
(Note that the cache may reduce the flicker after a while)