Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx - "force" 200 cache response instead of 304

Tags:

nginx

Is it possible somehow to force a 200 (cache) response instead of a 304 not modified for static files? If so you could potentially save a lot of server requests and speed up the loadtime considerbly for returning visitors.

like image 345
rob Avatar asked Jan 25 '11 18:01

rob


1 Answers

I've found Expires alone does not properly set the behavior. Below has been a sure fire:

# Set cache
expires 1M;
add_header Pragma public;
add_header Cache-Control "public";

This going in your location block desired..

I also think there is a lot of misleading information out there on this.. That 200 is somehow the same as 200 (cache).

From my understanding:

200 - server request - transfer OK 200 (cache) - OK - no server request (from cache) 304 - server request - no transfer (not modified)

200 (cache) as I understand it does NOT make a server request at all.

like image 64
Ryan Thompson Avatar answered Sep 28 '22 06:09

Ryan Thompson