Allright! I managed to solve the issue now that @jonsully kindly pointed me in the right direction!
For future reference if anyone else get problems with a Gatsby service-worker and a Netlify form.
- The netlify form is communicating with Netlify through a AJAX POST request. AJAX is a combination of javascript and XML.
- If you use a combination of gatsby-plugin-offline and gatsby-plugin-manifest the Gatsby serviceworker is configured with workbox under the hood and doesnât really distinguish between POST or FETCH requests.
- When you define WHAT gatsby-plugin-offline should precache you can do it in 2 different ways inside the gatsby-config.js file:
- define page(s) to be prefetched:
example:
resolve: "gatsby-plugin-offline",
options: {
precachePages: [
`/index.html`,
`/en/awesomeArticles/*`,
`/pl/moreAwesomePages/*`,
],
},
},
This generally wonât give you any problems with netlify forms - when you define pages this way - any images, json, js and so forth will be precached for the pages making them work offline.
- You can also specify a list of filetypes to be precached for the full page - by adding âglob-patternsâ to the workbox-config:
resolve: "gatsby-plugin-offline",
options: {
precachePages: [
`/index.html`,
`/en/awesomeArticles/*`,
`/pl/moreAwesomePages/*`,
],
workboxConfig: {
globPatterns: [
"**/*{.js,.json,.webp,.webmanifest,.woff,.woff2,.ttf,.eot,.css,.mjs,.svg,.mp3,icons/icon*,.ico}",
],
},
},
},
},
Precaching .js files like this, will cause the serviceworker to âcatchâ any AJAX POST requests from your form - and they never get to Netlify.