From 67013b9642a86ec603ec71000bb69f2725e2039e Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sat, 30 May 2020 20:55:05 -0700 Subject: [PATCH] Add preloading hints for default fonts This adds preloading hints to rustdoc's HTML for certain fonts that are always loaded from the server. This enables browsers to improve loading performance of the page. --- src/librustdoc/html/layout.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index ea65b3905272e..14c7880a985e8 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -129,7 +129,14 @@ pub fn render( suffix = page.resource_suffix ) } else { - String::new() + // No CSS extension means there's probably no font overrides, so + // we add a preloading hint for fonts we always load remotely. + format!( + "\ + ", + font_attrs = "rel='preload' type='font/woff' as='font'", + static_root_path = static_root_path + ) }, content = Buffer::html().to_display(t), static_root_path = static_root_path,