Theme Switcher code JS

Good morning,
I use the “Theme Switcher” object in the navigation bar present on all pages.
This works, but the JS code is present in the header of each page.
Can you offer me a solution for the code to be in a separate JS file.
Thanks in advance

I believe the code is put in the beginning of the page so that it loads straight away, if it was in a separate js file (which is usually at the end of the html file) then you could experience a flicker where it is loading the default css theme, then switching to the dark theme after the page has loaded.


Thanks Richards.
I understand that the JS code must be executed before displaying the page.
It might be interesting to link a JS file that is not inserted at the end of the HTML page by Bootstrap Studio, but at the beginning in the header.



1 Like

Thanks kuligaposten,
Your example optimises the JavaScript code and improves the interface by displaying the selected icon.

If you will do something similar remember that the Default Color Mode in the settings dialog must be ‘light’ or ‘dark’ if you choose ‘auto’ it will trigger Bootstrap Studio’s javascript code in the head section