REST response gets cached for guest user requests I've implemented kind of a page hit counter as REST request. The article page renders a JS into the page that does a jQuery.getJSON to the REST resource later.

So far that works fine. The page is delivered from cache (X-Drupal-Cache:"HIT") and the browser does an extra request to the REST resource (/api/v1/check/l/1?_format=json).

Unfortunately the REST handler is not called for guest user views. Instead, Drupal delivers the cached response. It only works for authenticated users.

For guest I get 

Cache-Control:"must-revalidate, no-cache, private"
X-Drupal-Dynamic-Cache:"UNCACHEABLE"


BUT:

X-Drupal-Cache:"HIT"


And the REST handler is not executed. My REST response is 

return (new ResourceResponse($rc))-&gt;addCacheableDependency(null);


Thanks
This is probably the page cache for anonymous users, which works independently from the dynamic cache.

You can disable it with this command:

\Drupal::service('page_cache_kill_switch')-&gt;trigger();


You can trigger this anywhere in your code and it will be valid for any response  you send for the request. So this should also work for a REST response.