Ignore Cache Control of the browser

Hello,

I’m looking for an option to ignore cache control header parameter passing from browser. The issue is that wherever there is a hard reload, CF bypasses the cache and sens a request to my server.
I’d like to be able to ignore cache-control parameter an make CF return the cache version despite the hard reload on the browser side.
How can I set it up?

Regards

Cloudflare caches static files by default (images, JS, CSS etc). For HTML, you need to create a Page Rule with a Cache Level: Cache Everything. If you add an Edge TTL instruction to the same page rule, it will override the Cache-Control set by the origin and cache the HTML at the edge (Cloudflare datacenters) for the specified time period (or less).

It caches HTML as well atm, since I can see that in the response the cache status is HIT.
My point is, how can I disallow browsers to request with no-cache headers and bypass my cache?

Hi Levon,

Have you tried looking at Cloudflare Workers? I think it might be possible by using the Workers by doing something like:

async function removeCacheHeader(request) {
    let request = event.request
    let response = await fetch(request)

    // We want to alter the headers, so copy the response headers
    response = new Response(response.body, response)

    // If it has a 'Cache-Control' header, try to delete it
    if (response.headers.has("Cache-Control") {
        response.headers.delete("Cache-Control")
        // Or play with: response.headers.set('cache-control', 'max-age=259200'); as sample (3 days)
        return fetch(request)
    }
}

addEventListener('fetch', event => {
    event.respondWith(removeCacheHeader(event))
})

The above code is just from the top of my head, untested but it might give you an idea of what could be possible. Maybe someone with more experience can comment, but I do alter some headers in my wokers and that works great.

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