Need advice adding Cache-control code to my website

caching

#1

I’m trying to add Cache-control code to my website pages. I really only have 3 types of pages, which are:

1.) Pages I want everything cached on, meaning every user sees the same page.

2.) Pages I want nothing cached on. (Like pages from the staff interface used to edit the website, or session URLs.)

3.) Pages I only want images cached on, but nothing else.

My first question is; Can I just add Cache-control as a META tag? That would be the easiest. If so, can someone advise me on 3 ways to write code per my 3 needs above? For example, is this suited for #2 above?

Then I see examples everywhere on CloudFlare’s support pages like this. But again, I wouldn’t know how to put that in a META tag. Help!
cache-control: private, max-age=0, no-cache

Thank you,
Dan W.


#2

Cache control must be set in the headers, Cloudflare will not parse the Meta tag.


#3

Note that as default we essentially only cache static files (so 3 should be fine with default settings).

For 1 & 2 if you can specify those two categories of pages using a URL pattern, then page rules would be the way to do it:

For 1 you would set Cache Level: Cache Everything
For 2 you would set Cache Level: Bypass Cache


#4

If I didn’t want to use Page Rules, I could just put this in the HTTP Headers though, accomplishing the same thing, right? And any advice on the wording?

cache-control:private, max-age=0, no-cache

Thx,
Dan


#5

The Cache-Control header value needs to be public, max-age=SECONDS (see below article) for Cloudflare to cache static files. Note that Cloudflare will not cache HTML unless there is a page rule for “Cache Everything”.


#6

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