A script to purge cache of HTML pages
Closed this issue · 2 comments
Hmm, now that we're actively caching HTML pages with Cloudflare (as in the homepage itself, dashboard, and faq - actually pretty much only those 3 in our use case), we need a script to call Cloudflare's API to purge cache of those pages on every update (perhaps even allow it to read config.js to find out extra enabled pages and include those to the request).
I think I also still need to make sure the current Cache-Control for HTML pages will still be able to deliver the latest change ASAP. I think it already do, but just a self-reminder.
Now for those who isn't aware, the last few commits were dedicated into making safe.fiery.me-exclusive Cache-Control, mainly to cache HTML pages (the frontend).
It's to ensure the frontend itself loads as fast as possible anywhere on the planet Earth.
API calls are not cached, so those will still lag behind in those faraway countries, but having the pages load fast should be desirable to overall user experience.
At the moment the frontend is being cached for about 12 hours. After making this script, I presume it should be fine to raise that to 30 days right away? Not sure though, still need to see if browsers are truly respecting must-revalidate
Cache-Control or not, and how often do they do it.
Seems like I had completely wrong knowledge of this whole Cache-Control thing (if not all, then most).
I've just read some articles and I think I've finally figured out the proper way to achieve what I want.
I'll make a commit in a few hours after some more learning and testing, I think.
Ok, b431d11 does it.
Basically, now proxy server will cache those HTML frontends for 30 days, but clients/browsers will not.
From what I can tell, clients will still cache them, but clients will use ETag to check whether the file in the proxy server has changed, and if not, skip download.
And, since all that needs to be done is just to connect to proxy server, as in, not having to wait for proxy server to fetch from origin server, First Time Byte (FTB) is great worldwide.
Then when it comes to having to update, the new yarn cfpurge
script is all that needs to be run to purge cache of those HTML frontends in proxy server.
I even made a shortcut script named yarn pm2restart
to restart PM2 of the safe then run the purge script (so my workflow is pretty much only yarn pull; yarn pm2restart
, huh).