Can't load external CSS via Javascript

I’m trying to load a CSS file through javascript with this code:

const linkCSS = document.createElement('link');
linkCSS.href = "./css/style.css";
linkCSS.rel = "stylesheet";
document.head.appendChild(linkCSS);

The CSS file contains this:

@font-face {
    font-family: BankGothic Md Bt;
    src: url(../assets/typo/BankGothic.ttf);
}

@font-face {
    font-family: Gotham;
    src: url(../assets/typo/Gotham.ttf);
}

I want to load my custom fonts to the plugin. I don’t have a HTML index file, is it possible to do it only with JavaScript?

Thanks!

Seems it does load CSS successfully but the font loading doesn’t work, anyone know why it could be?

Can you encode font as base64? Will it change anything? Can you also try Woff and Woff2? TTF is kind of non-optimal these days in browsers. In Internet Explorer EOT was a way to go and last one to try is the OTF. But maybe it is just not supported at all

I just converted the .TTF and already tried now with .woff, .woff2 and .eot and none of them works either.

I’m trying to load the font url as BASE64 but somehow when I replace the <<BASE64>> with the base64 font characters it all goes white.

This is the font-face code and I replace the <<BASE64>> with the base64 characters.

This is how it looks when I replace it:

And this doesn’t work either.

Any ideas?

@kerrishotts Do you have any suggestions for this issue?

My blan B is to use .svg for my fonts but is not the most optimal option for this.

UXP doesn’t support font-face yet which is why the fonts don’t get loaded.

2 Likes

Thanks for letting us know this Indranil. Is it planned to be an added feature at some point or this won’t ever happen?

Though font-face isn’t prioritized in the upcoming releases for now but this is something that’s in the feature list of the UXP team and isn’t something that’s in the won’t ever happen bucket.

1 Like

Thank you Indranil, meanwhile I used .svg fonts and works great by now!

1 Like