How to debug If-modified-since with http_reply_from_files?

I’m writing an http server that (amongst other things) sends JavaScript to the browser:

:- use_module(library(http/http_files), [http_reply_from_files/3]).
:- http_handler(static(.),
                http_reply_from_files(static(.), [cache(false)]),
                [prefix]).

Sometimes this doesn’t send the latest version source file to the browser – I need to use chrome://settings/clearBrowserData?search=cache and click “Cached images and files”.

Any suggestions for figuring out why updated files don’t get sent to the browser? I’ve turned on every debug flag I could find in the http package sources, but I don’t see any output that corresponds to “If-modified-since” and the contents of the response. (Anyway, with cache(false), “If-modified-since” should be ignored.)
I’m using Chrome on Linux, but don’t mind switching to Firefox if that has better debug support.
In desperation, I’ll use wireshark or tcpdump, but I’m assuming it’ll just show that a 304 response was sent back and I’ll still need to dig through the http libraries to figure out why.

Both have a pretty similar and good debug console. To sniff the requests, simply use ?- debug(http(request)). I guess the problem is with the browser caching the page and not trying a if-modified-since. I’ve never understood the exact logic by the browser on when to check with the server and when not. It might actually help to use cache(true), as this causes the server to send a modification time along with the file, so the browser can do the cheap if-modified-since request.

Otherwise, you need additional headers (Cache-control, etc). That is not part of the file reply predicates. It could be added, although in general I’d assume you want to allow caching for stuff that comes from files.

It turns out that this is a known problem with browsers and <script>.

(I had thought that debug(http(request)) wasn’t sufficient because I wasn’t seeing the the debug output for the script file … I should have trusted Jan’s code more!)

I added the following lines to my HTML and it now seems that script is fetched each time:

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
1 Like