feat-agency / vite-plugin-webfont-dl

⚡ Webfont Download Vite Plugin - Make your Vite site load faster
MIT License
302 stars 11 forks source link

[Feature Request] crossorigin option for generated link tag #44

Closed ghost closed 11 months ago

ghost commented 11 months ago

I have a case where the browser loads woff2 files more than once on refresh from the generated link tag. Since manually setting the crossorigin attribute fixes it, and I generate the index.html dynamically, it will be great to have it as a configuration option with the following type signature:

crossorigin: boolean | 'anonymous' | 'use-credentials'

When set it should generate:

boolean

<link rel="preload" as="style" href="/path/to/webfonts-[hash].css" crossorigin />
<link rel="stylesheet" href="/path/to/webfonts-[hash].css" />

anonymous

<link rel="preload" as="style" href="/path/to/webfonts-[hash].css" crossorigin="anonymous" />
<link rel="stylesheet" href="/path/to/webfonts-[hash].css" />

use-credentials

<link rel="preload" as="style" href="/path/to/webfonts-[hash].css" crossorigin="use-credentials" />
<link rel="stylesheet" href="/path/to/webfonts-[hash].css" />

Edit: the crossorigin attribute generated warnings and after further investigation my case of fonts loaded multiple times is due to the different fonts weights, so this feature is not needed. Leaving this here if someone else stumbles upon this case.