Skip to content

Commit 2701391

Browse files
CopilotdanielchalmersScarletKuro
authored
Reduce first-load icon flicker with font-display: block and preload guidance (#23)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com> Co-authored-by: ScarletKuro <19953225+ScarletKuro@users.noreply.github.com>
1 parent 1b1f670 commit 2701391

File tree

6 files changed

+64
-4
lines changed

6 files changed

+64
-4
lines changed

documentation/material_icons_usage.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,37 @@ To use the icons in your MudBlazor project, you can add the following CSS link t
1515
<link href="_content/MudBlazor.FontIcons.MaterialIcons/css/font.min.css" rel="stylesheet" />
1616
```
1717

18+
To reduce first-load flicker, preload the Material Symbols font files before loading the stylesheet:
19+
20+
```html
21+
<link rel="preload"
22+
href="_content/MudBlazor.FontIcons.MaterialIcons/font/MaterialIcons.woff2"
23+
as="font"
24+
type="font/woff2"
25+
crossorigin>
26+
<link rel="preload"
27+
href="_content/MudBlazor.FontIcons.MaterialIcons/font/MaterialIconsOutlined.woff2"
28+
as="font"
29+
type="font/woff2"
30+
crossorigin>
31+
<link rel="preload"
32+
href="_content/MudBlazor.FontIcons.MaterialIcons/font/MaterialIconsRound.woff2"
33+
as="font"
34+
type="font/woff2"
35+
crossorigin>
36+
<link rel="preload"
37+
href="_content/MudBlazor.FontIcons.MaterialIcons/font/MaterialIconsSharp.woff2"
38+
as="font"
39+
type="font/woff2"
40+
crossorigin>
41+
<link rel="preload"
42+
href="_content/MudBlazor.FontIcons.MaterialIcons/font/MaterialIconsTwoTone.woff2"
43+
as="font"
44+
type="font/woff2"
45+
crossorigin>
46+
<link href="_content/MudBlazor.FontIcons.MaterialIcons/css/font.min.css" rel="stylesheet" />
47+
```
48+
1849
Alternatively, you can use the following CDN links:
1950

2051
```html

documentation/material_symbols_usage.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ To use the icons in your MudBlazor project, you can add the following CSS link t
1515
<link href="_content/MudBlazor.FontIcons.MaterialSymbols/css/font.min.css" rel="stylesheet" />
1616
```
1717

18+
To reduce first-load flicker, preload the Material Symbols font files before loading the stylesheet:
19+
20+
```html
21+
<link rel="preload"
22+
href="_content/MudBlazor.FontIcons.MaterialSymbols/font/MaterialSymbolsRounded.woff2"
23+
as="font"
24+
type="font/woff2"
25+
crossorigin>
26+
<link rel="preload"
27+
href="_content/MudBlazor.FontIcons.MaterialSymbols/font/MaterialSymbolsOutlined.woff2"
28+
as="font"
29+
type="font/woff2"
30+
crossorigin>
31+
<link rel="preload"
32+
href="_content/MudBlazor.FontIcons.MaterialSymbols/font/MaterialSymbolsSharp.woff2"
33+
as="font"
34+
type="font/woff2"
35+
crossorigin>
36+
<link href="_content/MudBlazor.FontIcons.MaterialSymbols/css/font.min.css" rel="stylesheet" />
37+
```
38+
1839
Alternatively, you can use the following CDN links:
1940

2041
```html

src/MudBlazor.FontIcons.MaterialIcons/wwwroot/css/font.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,39 @@
33
font-family: 'Material Icons';
44
font-style: normal;
55
font-weight: 400;
6+
font-display: block;
67
src: url(../font/MaterialIcons.woff2) format('woff2');
78
}
89

910
@font-face {
1011
font-family: 'Material Icons Outlined';
1112
font-style: normal;
1213
font-weight: 400;
14+
font-display: block;
1315
src: url(../font/MaterialIconsOutlined.woff2) format('woff2');
1416
}
1517

1618
@font-face {
1719
font-family: 'Material Icons Round';
1820
font-style: normal;
1921
font-weight: 400;
22+
font-display: block;
2023
src: url(../font/MaterialIconsRound.woff2) format('woff2');
2124
}
2225

2326
@font-face {
2427
font-family: 'Material Icons Sharp';
2528
font-style: normal;
2629
font-weight: 400;
30+
font-display: block;
2731
src: url(../font/MaterialIconsSharp.woff2) format('woff2');
2832
}
2933

3034
@font-face {
3135
font-family: 'Material Icons Two Tone';
3236
font-style: normal;
3337
font-weight: 400;
38+
font-display: block;
3439
src: url(../font/MaterialIconsTwoTone.woff2) format('woff2');
3540
}
3641
body {
@@ -115,4 +120,4 @@ body {
115120
direction: ltr;
116121
-moz-font-feature-settings: 'liga';
117122
-moz-osx-font-smoothing: grayscale;
118-
}
123+
}

src/MudBlazor.FontIcons.MaterialIcons/wwwroot/css/font.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MudBlazor.FontIcons.MaterialSymbols/wwwroot/css/font.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
font-family: 'Material Symbols Outlined';
44
font-style: normal;
55
font-weight: 400;
6+
font-display: block;
67
src: url(../font/MaterialSymbolsOutlined.woff2) format('woff2');
78
}
89

910
@font-face {
1011
font-family: 'Material Symbols Rounded';
1112
font-style: normal;
1213
font-weight: 400;
14+
font-display: block;
1315
src: url(../font/MaterialSymbolsRounded.woff2) format('woff2');
1416
}
1517

1618
@font-face {
1719
font-family: 'Material Symbols Sharp';
1820
font-style: normal;
1921
font-weight: 400;
22+
font-display: block;
2023
src: url(../font/MaterialSymbolsSharp.woff2) format('woff2');
2124
}
2225

@@ -66,4 +69,4 @@
6669
direction: ltr;
6770
-moz-font-feature-settings: 'liga';
6871
-moz-osx-font-smoothing: grayscale;
69-
}
72+
}

src/MudBlazor.FontIcons.MaterialSymbols/wwwroot/css/font.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)