Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: load primary font in a non-blocking manner #448

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion common_design.theme
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,14 @@ function common_design_preprocess_html(&$vars) {
];
$vars['page']['#attached']['html_head'][] = [$js_detection, 'js-detection'];

// Construct a <link>s for Roboto: two that preconnect to Google Fonts, for a
// Construct <link>s for Roboto: two that preconnect to Google Fonts, for a
// nominal performance improvement, and the link to the CSS file itself.
//
// To load the font in a totally non-blocking manner, we are using the media
// attribute to specify print until the fonts load, then we remove it with JS.
// There is no <noscript> in place, so the fonts won't load on non-JS browsers
// by design.
//
// To edit the font selection, visit the following URL:
//
// @see https://fonts.google.com/share?selection.family=Roboto:ital,wght@0,300;0,400;0,500;0,700;0,900;1,400;1,700
Expand All @@ -540,6 +545,8 @@ function common_design_preprocess_html(&$vars) {
$roboto_default = [
'rel' => 'stylesheet',
'href' => 'https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;0,500;0,700;0,900;1,400;1,700&display=swap',
'media' => 'print',
'onload' => 'this.onload=null;this.removeAttribute(`media`);',
];


Expand Down
Loading