Add Cache-Control Headers
Image requests to a site upload image (media gallery) results in the following cache-control
request header:
cache-control: max-age=0
Here's an example image (temporary): https://www.chicagoganghistory.com/wp-content/uploads/2016/12/71291929_916584865386438_5533074164048461824_n-6-300x216.jpg
To improve performance the Cache-Control
headers can be increased from max-age=0
to something else via the .htaccess
file. This appears to be a reasonable write-up describing how that's done: https://robinroelofsen.com/browser-caching-htaccess-apache.
I tried doing that myself with a custom wp-cli-docker
image and deployed to production. The build goes through fine with the addition of the <IfModule mod_headers.c>
block but no change is seen in the Cache-Control headers. This means I'm either doing something wrong (perhaps this change needs to be added at the .htaccess
in the uploads folder and not from the htaccess
template in the Init Container) or mod_headers.c
isn't available. But I'm not sure which it is.
How can we add caching? And can this be done in the main project to improve site performance for all users? I can submit a pull once we've figured out where's the right place to add the goods assuming it can be done without modification to the upstream image used by the init container.