Way to get 304 responses from file protocol

457 views Asked by At

Is there any way to get a 304 Not Modified (as opposed to a 200 and the file's contents) response from the file system if, for instance, I access file:///img.png and the browser already has this file cached?

I mean this as in, can I do this without setting up a file server that communicates over http? Or, is this just a limitation of the file protocol.

1

There are 1 answers

4
Eric J. On BEST ANSWER

You cannot. It is a limitation of the file: protocol. In fact, that protocol does not define 200 or 304 codes. Those codes are specific to the http protocol.

As to whether the browser may use a cached copy of the file, the client is responsible for loading the file resource itself. There is no server component to know whether or not the file was modified. The only component in the interaction that could know is the browser, and the only way for it to know for sure is to load the file.

It could check the timestamp in theory, and perhaps some browsers do, but having the same timestamp as a previous load does not guarantee the file is unmodified. At least on some systems, the last modified time can be changed via a system call.