问题
I have a cgi program written in C that outputs gif images, writing them to stdout, and preceded by the cache control lines,
fprintf(stdout,"Cache-Control: max-age=99999\n");
fprintf(stdout,"Content-Length: %d\n",nbytes);
fprintf(stdout,"Content-Type: image/gif\n\n");
And the CGI is invoked from an HTML page with a tag of the form
<img src="http://example.com/cgi-bin/gifprogram.cgi?query_string">
where query_string is the usual form variable=value&etc describing the gif to be generated by the program. It works okay (at least to the extent I've tested it), but images are re-downloaded whenever I reload the HTML page, despite the max-age emitted by the program.
Static images, i.e., where src="http://example.com/image.gif" points to a file, seem to work okay, and they're just reloaded from the client browser cache. So I'm guessing (totally guessing) the problem's related to the fact that the tag's dynamically running a program on the server, and that fact somehow overrides the max-age. Is that right? Or what? And how, if there's a way, can I get the browser to re-use its cached images when the page is reloaded?
Note: I'm testing with Linux (Slackware 14.2) firefox 45.2.0, but have seen the same behavior with Mozilla and Konqueror. Haven't had an opportunity to try Windows.
Edit Thanks @JefréN for solution, and here's a demo of now-working program,
http://www.forkosh.com/gifscroll.xq?message=%5CLARGE%5Cbf%7B%5Chspace%7B8%7D%5Cfbox%7B%5Cfbox%7B%7B%5C%20Thanks,%5C%20JefreN%5C%20%7D%7D%7D%5Chspace%7B8%7D%7D&nscroll=4&nflicker=6&fg=4&bg=0&margin=52&njitter=4&vjitter=.50&password=forkosh&nzoom=6&zoomn=-10%20&%20bg2=0&nchk=0&btype=3&bmargin=24&bwidth=48&bshape=1&bsfrac=.50&bfrac=.43&cband=3,5,6,7,13,5,11,2&fgb1=-1&fgb2=-99
来源:https://stackoverflow.com/questions/40840600/img-tag-not-respecting-max-age-and-unnecessarily-reloading-images