Is it possible to pull data from a local json file hosted on a worker?

Instead of having a giant array at the bottom of my index file is it possible to move this to a local json file hosted on the worker? Or should I fetch it from somewhere for every request?

You could try using webpack to import the file as usual and then during build it’ll bundle it all into one worker file

1 Like

Yes, this would be the best way to do this IMHO; there’s no way to get access to the filesystem from inside the worker, so there’s nowhere for that script to actually go.

You could store the array in Workers KV or you could store the array in a file on your origin server which you cache on Cloudflare’s edge and fetch/parse it.