phphttp-headerscdncloudflareexpires-header

What HTTP headers for static resources to be correctly cached by CloudFlare?


I have a web application where some images are generated by PHP.

For those that are familiar, these are badges that you can put on your GitHub's projects (in the README for example).

What headers do I need to set with PHP, when generating those images (.svg), so that CloudFlare caches them for a day?

FYI I am using the free plan.

CloudFlare's documentation is very lacking IMO, I can't find anything related to static resources and TTL. To be clear: I'm not caching HTML, I'm caching static resources (that are generated by PHP).


Solution

  • Cloudflare respects what you put in HTTP headers. You just need to set a cache-Control: max-age value when returning your images. See this SO question.