fonts referenced by LINK tags for preloading fonts are not included

Created on 3 January 2024, 9 months ago
Updated 29 January 2024, 8 months ago

Problem/Motivation

My site's theme does this:

  $fonts = [
    'some-font-name.otf',
  ];
  foreach ($fonts as $font) {
    $variables['#attached']['html_head'][] = [[
      '#tag' => 'link',
      '#attributes' => [
        'rel' => 'preload',
        'as' => 'font',
        'href' => $fonts_path . $font,
        'crossorigin' => 'anonymous',
      ],
    ], 'gds_preload_font_' . $font,
    ];
  }

The Tome output HTML has the LINK tag in the HTML HEAD:

<link rel="preload" as="font" href="/profiles/path-to-fonts/fonts/some-font-name.otf" crossorigin="anonymous" />

But the file itself does not get copied to the html output folder.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: works as designed

Version

1.0

Component

Tome Static

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @joachim
  • πŸ‡¬πŸ‡§United Kingdom joachim
  • Merge request !17Added linked fonts to HTML asset paths. β†’ (Open) created by joachim
  • Status changed to Needs review 8 months ago
  • Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 8 months ago
    Waiting for branch to pass
  • Status changed to RTBC 8 months ago
  • πŸ‡ͺπŸ‡ΈSpain alvar0hurtad0 CΓ‘ceres

    The Mr fixes the issue for me.

  • Status changed to Postponed: needs info 8 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Doesn't your CSS have a font-face declaration somewhere that also loads the font?
    Is the issue that the font doesn't load AT ALL or that it doesn't preload?
    If it doesn't load at all, I'm not sure this is the right fix.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    I don't know enough about front-end code to answer any of those questions, sorry!

    Without this patch, the static version of the site gets 404 errors in the browser console for the fonts:

    > GET http://bi-com-giotrif-static-tome.ddev.site/profiles/bihub/bi_gds_profil...

  • Status changed to Closed: works as designed 8 months ago
  • πŸ‡¬πŸ‡§United Kingdom joachim

    I've had some help from a front-end dev, and investigated some more.

    The fonts that are referenced in the CSS files are correctly getting extracted in getCssAssets() and then exported.

    The problem here was that the fonts referenced in the LINK tags are not the same ones that are used in CSS! They're not used at all in fact!

    So this is a case of PEICPC (Problem Exists in Crappy Project Code).

    Closing, and sorry for the noise.

Production build 0.71.5 2024