Open farukcan opened 1 year ago
Thank you my friend.
I will try this soon.
It's a challenge because on one hand, we don't want to block the page loading by the script, on the other hand, we want to apply the theme before page loading...
Also, many people instead of using a <script>
tag, want to install it as a NPM package and import it with React, Vue, etc.
Thank you all. Following Mr. Farukcan's comment, I temporarily added the following code to the <head>
of my index.html
. This also avoids delays.
<script async crossorigin="anonymous">
var selectedTheme = localStorage.getItem("theme");
if(selectedTheme) {
document.documentElement.setAttribute("data-theme", selectedTheme);
}
</script>
hi @JieyueCoding it does not work for me
i mean, it need to be checked from blank tab each, not from already visited website
the glitch is still there
can i see your demo, please?
We must change theme before pageload event to avoid theme changing delay.
<head>
. It must be first loaded script that no need wait for page load.<script async crossorigin="anonymous" src="./theme-change.js"></script>
Thanks for your library!