Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Only load css that is actually needed Re: Only load css that is actually needed

#112302
JohnMotylJr
Participant

@rryter,

I am actually in a situation right now where i find myself using one standard stylesheet.css for my website. Now i started incorporating in snippets and giving the user the option to switch between styles. I could easily use jQuery to removeClass() addClass() over and over and over…

But what i am doing is introducing two additional stylesheets local to my index.html that is calling the themes. Im using Google’s prettify so i am accessing A LOT of different classes in different states. So instead of messing around with everything i just keep one stylesheet (theme) as default and when the user clicks the button for the other i merely disables the stylesheet.

I have been contimplating symatics about this for a little while now and realized that im stressing about nothing because it works, its quick, and if JS is disabled (for god knows why) than there will be a default stylesheet without the option to change.

This is the jQuery i am using, well a tiny bit just to show you.





$('#dark_theme_changer').live("click", function(e) {
$('link[title=dark_style]').prop('disabled',false);
$('link[title=light_style]').prop('disabled',true);
e.preventDefault();
});