I'm trying to change the bootstrap CSS style (I'll call it theme) of an HTML page. I want to switch between rows and cards style, which I have managed to do with some JavaScript and DOM manipulation. I also save the current theme in the local storage, so when refreshing the page I can set the theme chosen. I do all of this in the window.onload event.
The problem arises when I refresh the page: the theme is set correctly but it first shows the default one, and then it renders the one in localStorage.
How can I avoid this delay when setting the correct theme?