Usually I have in nginx config rules which does not allow cache all XMLHttpRequest:
map $http_x_requested_with $nocache_01 {
default 0;
XMLHttpRequest 1;
}
Is there a way to cache only GET Ajax request?
Usually I have in nginx config rules which does not allow cache all XMLHttpRequest:
map $http_x_requested_with $nocache_01 {
default 0;
XMLHttpRequest 1;
}
Is there a way to cache only GET Ajax request?
It's unshown, but assumed there's an if block in the config like so:
if ($nocache_01) {
...
}
Instead, by concatenating this variable with the request method, a more explicit check is possible i.e.:
if ($nocache_01$request_method = "1GET") {
...
}
Or, e.g., without using a map at all:
if ($http_x_requested_with$request_method = "XMLHttpRequestGET") {
...
}
Thank for AD7six for prompting. Now, my maps looks as it.
map $http_x_requested_with$request_method $nocache_01 {
default 0;
XMLHttpRequestGET 0;
~XMLHttpRequest(PUT|PATH|DELETE|POST) 1;
}
This is mean that XMLHttpRequest(PUT|PATH|DELETE|POST) will not be cached
fastcgi_no_cache $nocache_01;
fastcgi_cache_bypass $nocache_01;