Next.js Discord

Discord Forum

Next.js app simple static page still not being cached by CF

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo 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

Northeast Congo 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
Are u using the workers platform or the pages platform
@Cassin's Kingbird Are u using the workers platform or the pages platform
Northeast Congo LionOP
Self hosted.
On my own VPS
@Cassin's Kingbird Not really a Next.js issue
Northeast Congo 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 (?)
Not nextjs
@Northeast Congo Lion Self hosted.
Cassin's Kingbird
U can try cloudflares cache reserve
@Cassin's Kingbird U can try cloudflares cache reserve
Northeast Congo LionOP
I think that’s enterprise only
@Cassin's Kingbird It's cloudflare settings the response headers
Northeast Congo 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
@Northeast Congo 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
Northeast Congo LionOP
Why would CF add cache control headers though
@Northeast Congo 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
Northeast Congo LionOP
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
Northeast Congo LionOP
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
Northeast Congo 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
Northeast Congo LionOP
Jesus that's gonna be annoying
@Northeast Congo Lion Jesus that's gonna be annoying
Cassin's Kingbird
Is ur project static or dynamic?
Northeast Congo 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
Northeast Congo LionOP
Well the static assets are cached fine
Cassin's Kingbird
Theyre still in beta so a lot of stuff is free right now
Northeast Congo LionOP
My only issue is the actual HTML pages
Cassin's Kingbird
just try having a better hosting
Northeast Congo 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
Northeast Congo 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
Northeast Congo LionOP
I'll check out cache reserve
I thought it was enterprise but I guess that's another cache feature
@Northeast Congo 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
Northeast Congo LionOP
Yea I do use CF workers for a lot of things they are handy