Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent "304 Not Modified" in nginx?

I'm trying to disable all the caches in nginx for testing purpose.

I've set the following line

add_header Cache-Control no-cache;

I see that the page itself is not cached, but the images, css, and javascripts are. I suspect that this is because Firefox is getting "304 Not Modified" header.

Is there a way to prevent it?

P.S:

I think I found it myself. Firefox shows '200 OK' all the time now.

Is this correct way?

I've added

if_modified_since off;
add_header Last-Modified "";
like image 956
Moon Avatar asked Oct 04 '11 22:10

Moon


People also ask

How do you handle a 304 status code?

The HTTP 304 Not Modified client redirection response code indicates that there is no need to retransmit the requested resources. It is an implicit redirection to a cached resource.


2 Answers

Sounds right to me.

If the agent (in this case Firefox) says 200 OK, it means the transfer happened.

like image 96
Juan-José Del Río Holgado Avatar answered Sep 17 '22 15:09

Juan-José Del Río Holgado


Another way is to use a location directive:

location ~ \.(html|css|js)(.*)$ {
    expires -1;
    add_header Cache-Control no-store;
}
like image 43
Chauncery Avatar answered Sep 20 '22 15:09

Chauncery