Skip to content

Commit 3107d4e

Browse files
committed
Added google api font external link injection.
1 parent 1096bad commit 3107d4e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

gwt-material/src/main/java/gwt/material/design/client/font/FontResourceInjector.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class FontResourceInjector {
3131
private static Font defaultFont;
3232

3333
public static void inject(Font font) {
34+
injectGoogleFontLink();
35+
3436
String name = getDefaultFont().getName();
3537
if (createFontUrlLink(font.getResourceUrl())) {
3638
name = font.getName();
@@ -53,6 +55,19 @@ public static void setDefaultFont(Font defaultFont) {
5355
FontResourceInjector.defaultFont = defaultFont;
5456
}
5557

58+
protected static void injectGoogleFontLink() {
59+
LinkElement fontGoogleApisLink = Document.get().createLinkElement();
60+
fontGoogleApisLink.setRel("preconnect");
61+
fontGoogleApisLink.setHref("https://fonts.googleapis.com");
62+
getHeadElement().appendChild(fontGoogleApisLink);
63+
64+
LinkElement gstaticLink = Document.get().createLinkElement();
65+
gstaticLink.setRel("preconnect");
66+
gstaticLink.setHref("https://fonts.gstatic.com");
67+
gstaticLink.setAttribute("crossorigin", "");
68+
getHeadElement().appendChild(gstaticLink);
69+
}
70+
5671
protected static boolean createFontUrlLink(String resourceUrl) {
5772
if (resourceUrl != null) {
5873
LinkElement fontUrlLink = Document.get().createLinkElement();

0 commit comments

Comments
 (0)