How to set up cache-control to serve from Cloudflare?

Hi everyone,

I want to serve a Javascript file from Cloudflare, and I also want that file not to be cached at the user’s browser. I’ve set this cache-control.

max-age=0, public, s-maxage=1382400

But, it does not seems to work as Cache Analytics shows Dynamic as the cache type (Served from Origin, caching not configured) for this URL.

I really appreciate any help to configure this. If you want to further analyze the headers, this is that Javascript file:

Cloudflare only recognizes file type based on the extension.

So the URL does not contain any extensions e.g. .js. Cloudflare will treat it as non-cacheable content.

You need to create a page rule to force caching the URL like this:

1 Like

That makes sense. Yes, we do not have any extensions for this route.

Is there no way to force cache from the back-end (from our code) by setting any headers? We are already sending text/javascript as the Content-type. Page Rules is fine but if there’s a way to do this with code, we prefer that.

(If there’s no way, no worries, we’ll go with Page Rules :blush:)

Thanks again!

Unfortunately, yes :sweat_smile:

Cloudflare will only respect the cache-control (or the newer CDN-cache-control) header if your URL has an extension which is in the list of cacheable extensions.

1 Like

Thanks a lot for the fast help.

1 Like

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