Caching for cloudflare worker

I am trying to enable caching for my cloudflare worker. I have created a page rule like so:

However, when I make a request, I don’t see any “cf-cache-status”. Why not?

Specifically I’d like to get rid of theese GTMetrix errors:

Leverage browser caching for the following cacheable resources:
https://v2.thejewelleryroom.com/_nuxt/2028423588489b95c080.js (expiration not specified)

Any ideas?

You have to manipulate cache on the Worker code, using Cache API:

Also, on the dashboard you to set respect existing headers.

Another note, you could manipulate headers this way:

  let req = await fetch("https://www.example.com/script.js");
  let newHeaders = new Headers(req.headers);
  newHeaders.delete("GTMetrix");
  newHeaders.set("cf-priority", "30/0");

  return new Response(req.body, {
    status: req.status,
    statusText: req.statusText,
    headers: newHeaders
  });
2 Likes