Loading a library only for the front page I want to load JavaScript only on the home page of my site. I found this preprocess function but I don't know how to customize it for the home page:

function mytheme_preprocess_maintenance_page(&amp;$variables) {
  $variables['#attached']['library'][] = 'mytheme/cuddly-slider';
}


I was originally including the library I needed in every page of my site, but I only need it on the home page, so I need to figure this out.

Originally I had it in the .info.yml file like so:

libraries:
 - 'themename/library'


Any help is appreciated.
function mytheme_preprocess_page(&amp;$variables) {
  if (\Drupal::routeMatch()-&gt;getRouteName() == 'view.frontpage.page_1') {
        $variables['#attached']['library'][] = 'mytheme/cuddly-slider';
    }
}