ajhsu / blog

The external storage of my brain.
3 stars 0 forks source link

如何讓 Express 與 CloudFlare 搭配時能正確運作 #3

Open ajhsu opened 7 years ago

ajhsu commented 7 years ago

愛注意

  1. Cloudflare 預設會快取常見靜態素材
  2. 記得設定好 Page Rules
  3. 確定 Express 當中的 maxAge 有正確設置,因為預設值是 0 (也就是說預設會讓 Caching 關閉)。

If the Cache-Control header is set to "private", "no-store", "no-cache", or "max-age=0", or if there is a cookie in the response, then Cloudflare will not cache the resource. Otherwise, if the Cache-Control header is set to "public" and the "max-age" is greater than 0, or if the Expires headers are set any time in the future, we will cache the resource. Note: As per RFC rules, "Cache-Control: max-age" trumps "Expires" headers. If we see both and they do not agree, max-age wins.

See: https://support.cloudflare.com/hc/en-us/articles/202775670-How-Do-I-Tell-Cloudflare-What-to-Cache-

  1. 確定回應的 Header 是正確的: CF-Cache-Status: HIT

See: https://support.cloudflare.com/hc/en-us/articles/200169556-How-can-I-tell-if-Cloudflare-is-caching-my-site-or-a-specific-file-

如何快取全站?

如何快取全站,但排除管理頁面部分?

原始文章

https://support.cloudflare.com/hc/en-us/articles/200172256-How-do-I-cache-static-HTML-