astro-google-fonts-optimizer
astro-google-fonts-optimizer copied to clipboard
Added cache and retry attemps on fail
Partially fixes this issue: https://github.com/sebholstein/astro-google-fonts-optimizer/issues/1 with in-memory cache
Also sometimes I had crashes for unknown reasons during dev and build so I added that it'll retry refetching url in case of failure three times by default
npm package for testing: https://www.npmjs.com/package/@herob191/astro-google-fonts-optimizer
Also I wonder if this
const contents = await Promise.all(
urls.map(async (url) => {
try {
const css = await downloadFontCSS(url);
return { css }
} catch (err) {
return { url }
}
})
)
Can be replaced with this
const contents = await Promise.all(
urls.map(async (url) => {
const css = await downloadFontCSS(url);
return { css }
})
)
And then this
{contents.map(content => {
if (content.css) {
return (
<>
<style set:html={content.css} is:inline>
</style>
</>
)
}
return <link href={content.url} rel="stylesheet" />
})}
with this:
{contents.map(content => (
<>
<style set:html={content.css} is:inline>
</style>
</>
)}
Or is there more purpouse to it I don't see yet?
Or is there more purpouse to it I don't see yet?
The general idea was: when the network fails, we don't want to fail the build and simple load the fonts via the given URL.