1

I'm building an app that let's a user select a font combination within it's admin area. The combination is stored as string and the data is fetched on another frontend.

I now want to load the correct fonts within the app based on the variable, since I don't want fetch all fonts available.

What would be the best (mostly performance oriented) way to do that?

It's around 5 font combinations, with each 2 fonts and 2 weights.

maggiathor
  • 174
  • 6
  • you could just load in all the fonts, and then using react dynamicly set the font-family of the element you wish to have that font – Luke_ Sep 07 '20 at 09:48

1 Answers1

0

I suggest you add styles to your DOM with js code. this may help with it.

javascript beginner: add a dynamic style in javascript?

This way you can only add fonts that have been selected and maybe you would need to keep these fonts in backend or localStorage so that you know what styles you should load dynamically.

Alireza
  • 2,319
  • 2
  • 23
  • 35