Answer the question
In order to leave comments, you need to log in
How to perform an action depending on the presence of a cookie?
Hello!
You need to add a header and set a cookie if it doesn't exist. Tried like this:
map $http_cookie $res_pushed {
default "false";
"~*res_pushed" "true"; # Если есть кука res_pushed с любым значением, создаём $res_pushed = true. Иначе false.
}
server{
http2_push_preload on;
location /{
if ($res_pushed = "false") {
add_header Set-Cookie "res_pushed=true; Max-Age=20; Path=/"; # Если $res_pushed = false, создаём куку
add_header Link "</style.css>;rel=preload;as=style"; # и добавляем нужный заголовок
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question