Reverend Bubbles
Reverend Bubbles

Reputation: 1393

Change JS on CSS change

Something I'm playing with and need to know if it's even possible or am I spinning my wheels.

I have a personal project that's working on allowing me to change the CSS for a given site/page based on a dropdown selection. That part is going fine.

Something I'm realizing, though, is that I'm bloating up one single script.js with various ways to treat the elements in each style. Is there a way that I could make each style use a different JS file so that I can keep the style-relevant JS separate from each other? Also, can this be done without loading up ALL the JS files at the beginning but rather load them in as needed, like I'm doing with the CSS?

Upvotes: 0

Views: 45

Answers (1)

Tyler Becks
Tyler Becks

Reputation: 518

Webpack would help with splitting up the js into different files. Maybe something as simple as import/export?

To answer your question about only loading what you need, tree shaking will prevent your bundle from bloating. Dynamic imports might be helpful too.

Upvotes: 1

Related Questions