How to cache "web pages"?

This is my cache settings:

But this only assets files got cached, I’m wondering if there is a way to cache the web page(HTML markup) it self ? For example caching the response for ( content-type: text/html; charset=utf-8)

Should I use cloudflare workers to manually implement such a feature…?

Hi @wang,

You can use Wirkers to achieve this, or use Page Rules.

Just be careful when caching HTML if your site is not static.

Hi @domjh , thanks for the link, that helps!

I have another question which is related to this topic,
I was reading this article

and I just thought it must going to use the worker’s KV to “save” and “get” the cache(via a cache key), but I can’t find any related code for saving and retrieving cache from the article, so, is worker going to cache by default when using the fetch API… ?

Yes, normal behaviour as if it was passing through Cloudflare or following their cache-control headers if not in your domain, with the usual caveats that it might be evicted at need.

In a Worker you have the Cache API, and KV. You can take advantage of both.

Thanks @matteo !

Do you mean if the origin server sent a response with a Cache-Control header like:

Cache-Control: max-age=100

then the fetch is going to cache that response for 100s ?

For a maximum of 100s, as I said before, the caveats apply. The headers are an upper limit.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.