Skip to main content
Question

loadFontAsync in bulk at once


Vincent_Huss

Hi,

in the plugin API,
at initialization, i’m loading fonts with loadFontAsync this way

await figma.loadFontAsync({ family: "Baloo Paaji 2", style: "Medium" });
await figma.loadFontAsync({ family: "Baloo Paaji 2", style: "Regular" });
//about 10 loads like this one

is there a faster way to do a bulk load, something where i would pass all the parameters at once in an array ?

Thanks in advance.

This topic has been closed for replies.

2 replies

Gleb
  • Power Member
  • 4710 replies
  • July 15, 2024

You can use await promise.all instead of multiple awaits


Vincent_Huss
  • Author
  • Active Member
  • 29 replies
  • July 15, 2024

Thanks,

it does seems faster,
before, with all the awaits, it caused the hot reload to have weird behaviour, forcing me to focus on the Figma windows 2-3 times before the plugin could run.

It seems to be fixed now.
Here’s my code if anyone needs this

Promise.all([
    figma.loadFontAsync({ family: "Roboto Condensed", style: "Bold" }),
    figma.loadFontAsync({ family: "Roboto", style: "Italic" }),
     //load a bunch of fonts...
])
.then(res => {
    //code to be executed after the font loading
});

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings