Problem with browser cache and resource download - solve with Etags?

Problem with browser cache and resource download - solve with Etags?

by Daniel Neis Araujo -
Number of replies: 1
Picture of Core developers Picture of Plugin developers Picture of Translators
Hello,

i have just created an issue on tracker about this. Here is the link and the description:

http://tracker.moodle.org/browse/MDL-20042

"Hello,

while working on Federal University of Santa Catarina (http://moodle.ufsc.br), some users have reported the following situation:

- The teacher uploads file X
- Then, he links it through a resource on course A
- The student downloads file X for the first time
- Some time after, lets say 10 minutes, the teacher uploads another version of the file with the same name
- When the student tries to download the file again, the browser uses a cached version

I have tried to user the $CFG->filelifetime = 1, but the problems still persists. I have read about the HTTP cache mechanisms in http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html, and i think the follow happens:

* If we put the "Expires" too far in the future, the rest of message is discarded, including the new Last-Modified because the old Last-Modified is still valid
* If we put the "Expires" on the past, the browser will always touch the file in the server, discaregarding the Last-Modified, because the message isn't valid anymore

So, we cannot solve this problem using this basic header, we have to use ETags: "Entity tags are used for comparing two or more entities from the same requested resource". Basically, the server stores a hash of the file+timemodified (or just the file), and sends to client on the header response, if the hash matches one in the browser caches then it is used, otherwise the browser asks for the server to send the new file.

It will cause, of course, a performance overhead, but we can think about some way to cache things.

What do you think?"
Average of ratings: -