Next.js app simple static page still not being cached by CF
Unanswered
Cape lion posted this in #help-forum
Cape lionOP
I have a simple little page (static) and it shows the CF-Cache-Status being dynamic, this makes no sense to me. It's self hosted so having CF in the front is ideal for me.
65 Replies
Cape lionOP
I notice it also doesn't cache my next/image
But I set a rule for that because it has query strings
So I set cloudflare to ignore query strings for next/image
@Cape lion I have a simple little page (static) and it shows the CF-Cache-Status being dynamic, this makes no sense to me. It's self hosted so having CF in the front is ideal for me.
Cape lionOP
But this still persists, I ideally don't want to setup rules for each page..
Are u using the workers platform or the pages platform
@Cassin's Kingbird Are u using the workers platform or the pages platform
Cape lionOP
Self hosted.
On my own VPS
@Cassin's Kingbird Not really a Next.js issue
Cape lionOP
I mean CF would only be setting Dynamic because something on the response headers is making it questionable so I assume it might be a Next.js issue (?)
@Cape lion I mean CF would only be setting Dynamic because something on the response headers is making it questionable so I assume it might be a Next.js issue (?)
Cassin's Kingbird
It's cloudflare settings the response headers
Not nextjs
@Cape lion Self hosted.
Cassin's Kingbird
U can try cloudflares cache reserve
@Cassin's Kingbird U can try cloudflares cache reserve
Cape lionOP
I think that’s enterprise only
@Cassin's Kingbird It's cloudflare settings the response headers
Cape lionOP
Yeah but the cache control headers are determined by my app
Which would be Next.js
So much of my next app is being dynamically cached which is just stressing my server out. I don’t know if that’s because I have something incorrectly setup or it’s a Next thing
I mean a completely static page with literally one div and some text is being considered “Dynamic” by Cloudflare?? Seems like somethings either broken or I’m doing something wrong
@Cape lion Yeah but the cache control headers are determined by my app
Cassin's Kingbird
Cloudflare adds headers to the request
nextjs can't know by itself that it's being proxied via cf
Is it a static site or a dynamic site?
@Cassin's Kingbird Cloudflare adds headers to the request
Cape lionOP
Why would CF add cache control headers though
@Cape lion Why would CF add cache control headers though
Cassin's Kingbird
why wouldnt it
if ur vps is being proxied via cloudflare
Cloudflare adds 2-3 headers to it
It says Next.js sets the Cache Control header
Which would make sense
Cassin's Kingbird
There's 2 different things
Ur local cache (on the vps)
And cf cache
(what cf has cached)
Nextjs can control the local cache
Cloudflare isn't some smarty that it automatically knows by itself what to cache and what to not
I mean it also looks like Next.js appends a bunch of headers
Cassin's Kingbird
So by default, it forwards all requests to the vps
u gotta manually configure cache rules if u want cloudflare to cache them
Cape lionOP
For each page?
Cassin's Kingbird
which can be costly
u can set a wildcard
All requests to this domain should be cached or smthn
Cape lionOP
Jesus that's gonna be annoying
@Cape lion Jesus that's gonna be annoying
Cassin's Kingbird
Is ur project static or dynamic?
Cape lionOP
More dynamic
But there's multiple static pages
Cassin's Kingbird
try out appwrite
They'll automatically push ur static assets to a cdn and have the central node server running in a digitalocean container
Cape lionOP
Well the static assets are cached fine
Cassin's Kingbird
Theyre still in beta so a lot of stuff is free right now
Cape lionOP
My only issue is the actual HTML pages
Cassin's Kingbird
just try having a better hosting
Cape lionOP
Also have you used tRPC?
Cassin's Kingbird
Having something over an edge network rather than just one server will pretty much remove any sort of ddos issues
nope
also if u can't move from to any other hosting provider
Setup waf rules to try and block out any of those ddos attacks
Cape lionOP
Well I have all that setup fine for now
My only issue was that some pages were not being hit and showing dynamic from the cf-cache-status
Cassin's Kingbird
And then u can look into cache reserve
Cape lionOP
I'll check out cache reserve
I thought it was enterprise but I guess that's another cache feature
@Cape lion I thought it was enterprise but I guess that's another cache feature
Cassin's Kingbird
You could also go for cloudflare workers
The free tier is pretty generous if you site isn't clocking a lot of traffic
Cape lionOP
Yea I do use CF workers for a lot of things they are handy