Automatically generates headers configuration file for different hosting providers. Available providers are:
The task also transforms HTML link tags with resource hints eg. <link rel=preload>
into HTTP Link headers. Currently supports link tags with these rel types: preconnect
dns-prefetch
preload
prerender
prefetch
plugins: [
{
resolve: `gatsby-plugin-postbuild`,
options: {
'http-headers': {
enabled: true, // Enable the task
provider: 'netlify', // Headers config file provider [netlify, vercel, firebase]
headers: {
'[*]': { // Add headers to all paths
'X-Frame-Options': 'DENY',
'X-XSS-Protection': '1; mode=block'
},
'[pages]': { // Add headers to all pages generated by Gatsby
'X-Robots-Tag': 'noindex',
'Link': [
'<[asset:/static/logo.png]>; rel=preload; as=image', // Will be translated to </static/logo-[hash].png>; rel=preload; as=image
'</custom/path/to/script.js>; rel=preload; as=script',
],
},
'[assets]': {}, // Add headers to all immutable assets generated by Gatsby
'[page-data]': {}, // Add headers to page-data/* files
'[static]': {}, // Add headers to static/* files
'/path/to/unkown': {}, // Add custom path headers
'/about': {}, // Overwrite headers for specific page
'/static/logo.png': {}, // Overwrite headers for specific asset. Will be translated to `/static/logo-[hash].png`
},
security: true, // Adds some basic security headers
caching: true, // Adds essensial caching headers
removeLinkTags: true, // Remove the processed link tags
transformPathLinks: (links: Link[], path: string) => { // Callback for manipulating links under each path
return links.map(link => {
if (link.href === 'something') {
link.priority = 5
}
return link
})
}
}
}
}
]