Loading a library only for the front page
function mytheme_preprocess_page(&amp;$variables) {
  if (\Drupal::routeMatch()-&gt;getRouteName() == 'view.frontpage.page_1') {
        $variables['#attached']['library'][] = 'mytheme/cuddly-slider';
    }
}