Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A script to purge cache of HTML pages #15

Closed
BobbyWibowo opened this issue Jan 6, 2019 · 2 comments
Closed

A script to purge cache of HTML pages #15

BobbyWibowo opened this issue Jan 6, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@BobbyWibowo
Copy link
Owner

BobbyWibowo commented Jan 6, 2019

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.

@BobbyWibowo
Copy link
Owner Author

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.

@BobbyWibowo
Copy link
Owner Author

BobbyWibowo commented Jan 6, 2019

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).

@BobbyWibowo BobbyWibowo added the enhancement New feature or request label May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant