I'm looking to do some multithreading for my web application to improve performance and I've stumbled upon a head-scratcher. I'm currently developing on localhost (vite server) on Chrome.
Basically I have spawned a web worker. Then I created a SharedArrayBuffer.
At first, the SharedArrayBuffer was getting an error that it wasn't defined. I found out it is disabled unless you specify that you only want to allow same-origin on cors. So I added these headers to my vite server:
'Cross-Origin-Embedder-Policy': 'require-corp',
'Cross-Origin-Opener-Policy': 'same-origin',
It solved the problem with SharedArrayBuffer. But then, I started getting 304 errors for my worker
GET http://localhost:5001/js/searchWorker.js net::ERR_BLOCKED_BY_RESPONSE 304
If I allow cross origin with a wildcard, the web worker works, but the shared array buffer does not. And vice versa. I don't really understand as well because shouldn't it allow searchWorker.js because it's at the same origin (localhost)?
I don't really understand how to fix this issue!
Thanks!