Skip to main content
Vincent_Huss
Active Member
July 15, 2024
Question

loadFontAsync in bulk at once

  • July 15, 2024
  • 2 replies
  • 150 views

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
July 15, 2024

You can use await promise.all instead of multiple awaits

Vincent_Huss
Active Member
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
});