You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We must change theme before pageload event to avoid theme changing delay.
Step
if(typeofexports!="undefined"){module.exports={themeChange: themeChange}}else{varselectedTheme=localStorage.getItem("theme");// ADD line 1if(selectedTheme){// ADD line 2document.documentElement.setAttribute("data-theme",selectedTheme);// // ADD line 3}// // ADD line 4themeChange(true);}
Step
Add async attribute. And add this element to <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!
The text was updated successfully, but these errors were encountered:
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.
We must change theme before pageload event to avoid theme changing delay.
Add async attribute. And add this element to
<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!
The text was updated successfully, but these errors were encountered: