Advanced-administration-handbook icon indicating copy to clipboard operation
Advanced-administration-handbook copied to clipboard

Do not cache all JSON requests (API-REST) in nginx

Open javiercasares opened this issue 1 year ago • 4 comments

As per https://fosstodon.org/@webaware/110037286062251716

In nginx, we should not cache JSON requests in some cases.

if ($http_accept = "application/json") {
	set $no_cache 1;
}

javiercasares avatar Mar 17 '23 08:03 javiercasares

More information related:

  • https://snippets.webaware.com.au/snippets/caching-oembed-with-nginx/
  • https://aus.social/@rmccue/110020902246277742

Check publishing the REST API and also check caches from PUT, POST, DELETE at https://github.com/WordPress/Advanced-administration-handbook/blob/main/server/nginx.md#nginx-fastcgi_cache

javiercasares avatar Mar 17 '23 08:03 javiercasares

Some information related with JSON and the Fediverse at https://github.com/pfefferle/wordpress-activitypub/blob/master/includes/class-activitypub.php#L78-L81

javiercasares avatar Mar 17 '23 08:03 javiercasares

In nginx, we should not cache JSON requests in some cases.

if ($http_accept = "application/json") {
	set $no_cache 1;
}

as activitypub supports 4 different json-ish mime-types, it might be better not to cache if mimetype is text/html?

if ($http_accept != "text/html") {
	set $no_cache 1;
}

futtta avatar Mar 17 '23 17:03 futtta

@pfefferle any suggestions?

javiercasares avatar Apr 07 '23 10:04 javiercasares