I am trying to replicate polyfill.io functionality with Cloudflare Workers. Here is my code gist https://gist.github.com/asvny/b910527e6b8fe12c1051eb40bf8c138c
Say for example a person X visits our site: ( Currently how it works )
- On initial visit = Status: 200
Since the cache is empty it generates the response and caches it and then finally sends it with appropriate caching headers and ETag.
- On repeated visit = Status: 200
This time, the cache has the content, so it responds immediately but with status 200 code.
What I expect to happen is,
- On initial visit = status: 200
2: On repeated visit = status: 304
Since I send an ETag header, I expect the worker to check based on request’s If-none-match header and then respond with a 304 status code.
Note: There is no external fetch requests. All the content is generated in the worker script itself.
But am I not sure how to do it in Cloudflare worker? Thank you.