How to cache a page served by a worker?

The first page served by my worker is effectively static HTML and has quite a high bounce rate (i.e. visitors just read this page then leave), therefore I would prefer the first page is cached by Cloudflare and served from cache rather than spinning up a worker every time.

In the headers provided by the worker I’ve set the Cache-Control headers to be “public” with a “max-age” of 48 hours and my global cache policy is “cache everything”.

But the content still isn’t served by Cloudflare, it’s still spinning up a new worker to serve the static content.

How can I instruct Cloudflare to cache the initial content and to only spin up the worker for the subsequent page requests which have the cache-control headers set to no-cache?

Workers always run before the cache. If you have a path mapped to a Worker you won’t be able to first use the cache I am afraid.

1 Like

This topic is already discussed here

Also if you are concerned about billing

1 Like