Load library dynamically depending on settings My theme has a few settings that can be adjusted, one of them is style.

I want to load the libraries depending on the styles, but without writing them in the .libraries.yml

function my_theme_library_info_build() {
  $libraries = [];

  return $libraries;
}

function my_theme_library_info_alter(&amp;$libraries, $extension) {
  $tmp_theme = theme_get_setting( 'my_theme' );

  $libraries['my_theme.theme']['css']['theme'] = [
      'css/themes/' . $tmp_theme . '.min.css' =&gt; [],
  ];
}


This is what I've got so far but I have to clear the cache after changing the style.
I would implement this slightly differently. What you can do is combine all the different style css files into one, and use a className prefix instead of a file name prefix. So instead of having foo.min.css and bar.min.css you'll have 1 css file that's always included but has body.foo {} and body.bar {}  styles in them. 

Of course this gets easier with a preprocessor such as SASS: for every element you want to style you can wrap it in their respective body.foo or body.bar parents, without having to manually write body.foo in front of every element you want to style. So I highly recommend you use something like SASS for this, but it's not required at all.

The advantage of this method is I think it avoids problems with caching different CSS files since you're using only one. Also if your original goal of having separate CSS files was to keep them neat and separate then you can do that with your SASS files and they can be compiled into a minified single CSS file by your SASS processor.