RSS Cache Control
Brent Simmons reported to me that my blog’s RSS feed wasn’t updating in recent versions of NetNewsWire. They’ve added support for the Cache-Control
response header, and, for reasons unknown, my site was returning an interval of 2 days:
$ curl --head https://mjtsai.com/blog/feed/ HTTP/2 200 date: Wed, 08 Jan 2025 14:28:24 GMT server: Apache vary: Accept-Encoding,Cookie,User-Agent link: <https://mjtsai.com/blog/wp-json/>; rel="https://api.w.org/" etag: "9efc6f6ed8885592fcee58bc1685dcaf" cache-control: max-age=172800 expires: Fri, 10 Jan 2025 14:28:24 GMT content-type: application/rss+xml; charset=UTF-8
even though plain HTML content was only cached for 10 minutes:
$ curl --head https://mjtsai.com/blog/ HTTP/2 200 date: Wed, 08 Jan 2025 14:34:20 GMT server: Apache vary: Accept-Encoding,Cookie,User-Agent cache-control: max-age=3, must-revalidate content-length: 307509 last-modified: Wed, 08 Jan 2025 14:30:02 GMT cache-control: max-age=600 expires: Wed, 08 Jan 2025 14:44:20 GMT content-type: text/html; charset=UTF-8
I spent a while trying to figure out why WordPress would do that, but it turns out to be a default set by my server provider, DreamHost. RSS feeds fall under the default file type even though they are more likely to change frequently.
There are various ways to override this using Apache’s .htaccess file. Simmons is using this for his feed:
<Files "rss.xml"> <IfModule mod_headers.c> Header set Cache-Control "max-age=300" </IfModule> </Files>
But I don’t want to list each file separately because this blog has many feeds, e.g. one for the comments on each post. What seems to work is setting the expiration by MIME type:
<IfModule mod_expires.c> ExpiresActive on ExpiresByType application/rss+xml "access plus 300 seconds" ExpiresByType application/atom+xml "access plus 300 seconds" </IfModule>
Please let me know if you run into any problems with this.
Previously:
2 Comments RSS · Twitter · Mastodon
This likely explains why I receive your posts in batches every couple of days
@matt Sorry about that. Hopefully this will fix it. A lot of RSS reeders seem to ignore the header so it wasn’t evident to me that there was a problem.