Gatsby plugin to add the crossorigin attribute to every <link rel="preload"> tag
npm install gatsby-plugin-preconnectQuickly add a tag for every specified domain.





 !npm
npm install --save gatsby-plugin-preconnect
It simply adds a to the page (see the
Resource Prioritization - Preconnect
guide).
``javascript`
// In your gatsby-config.js
plugins: [
{
resolve: 'gatsby-plugin-preconnect',
options: {
domains: ['https://foo.com', 'https://bar.com'],
},
},
]
crossOrigin is set to true by default but it can be customized, below all the available options
`js`
plugins: [
{
resolve: 'gatsby-plugin-preconnect',
options: {
domains: [
'https://foo.com',
'https://bar.com',
{ domain: 'https://enablecors.com', crossOrigin: true },
{ domain: 'https://disablecors.com', crossOrigin: false },
{ domain: 'https://corswithanonymous.com', crossOrigin: 'anonymous' },
{ domain: 'https://corswithcreds.com', crossOrigin: 'use-credentials' },
],
},
},
]
All the available values for crossOrigin are listed below, every other value makes the plugin throw an error
| Value | Equivalent value |
| ------------------- | --------------------- |
| undefined | "anonymous" |true
| | "anonymous" |"anonymous"
| | "anonymous" |"use-credentials"
| | "use-credentials" |false
| | (attribute not added) |
PR or issues are welcome 👋
#### Notes
- if you want to work on the plugin sources, remember that you need to npm run build on the rootnpm run plugin:link` to locally use it
then, in every test project, you need to run
Thanks goes to these wonderful people (emoji key):
Stefano Magni 💻 📖 | Dugagjin Lashi 💻 👀 | Sean King 🤔 | Andrew Schneider 💻 📖 ⚠️ | Andreas Donig 🤔 |
This project follows the all-contributors specification. Contributions of any kind welcome!