Can I get the absolute path to the frontpage in theme_preprocess_html? Is it possible to get the absolute path to the homepage or &lt;front&gt; eg: https://www.domain.com/homepage in the theme_preprocess_html hook? I tried global $base_url but it throws an error.
I used \Drupal::urlGenerator()-&gt;generateFromRoute('&lt;front&gt;', [], ['absolute' =&gt; TRUE]); from one of the comments in:

How to get the base URL of a site

Here is the entire working snippet:

/**
 * Implements hook_preprocess_html().
 */
function mytheme_preprocess_html(&amp;$variables) {

  // Modify if we're on nodes
  if ($node = \Drupal::request()-&gt;attributes-&gt;get('node')) {
    // Get the node-type
    $nodetype = $node-&gt;getType();
    // Switch class for node-type
    switch ($nodetype) {
      case "landing":
        // prefetch frontpage from landing pages
        $frontpage_path = \Drupal::urlGenerator()-&gt;generateFromRoute('&lt;front&gt;', [], ['absolute' =&gt; TRUE]);
        $prefetchfront = [
          '#tag' =&gt; 'link',
          '#attributes' =&gt; [
            'rel' =&gt; 'prefetch prerender',
            'href' =&gt; $frontpage_path,
          ],
        ];
        $variables['page']['#attached']['html_head'][] = [$prefetchfront, 'prefetch'];
      break;
    }
  }
}