I'm looking to give users the ability to switch a theme and I have 2 seperate style sheets, 1 for each theme.
I do something like this to switch it
toggleTheme() {
if (usingWhiteTheme) {
$('link[href="white.css"]').attr('href', 'dark.css');
usingWhiteTheme = false;
} else {
$('link[href="dark.css"]').attr('href', 'white.css');
usingWhiteTheme = true;
}
}
However it causes hideous flicker the first time as it loads the file from the server. After that it switches without a flicker.
How can I preload this style and then load it from the cache? Should I even use cache or is there someway more reliable for users that turn off cache? Can I stuff it into local storage?