Images changed on disk do not refresh
If you include an image via markdown as  or <img src="image.png">, evaluate that cell, and subsequently change the image on disk somehow, the image in the notebook still shows the old version. Halting the kernel and reopening the notebook sometimes works to refresh the image, but it seems unreliable. I would expect that re-evaluating the cell should be sufficient to show the new image.
The kernel won't be involved in this, it's all up to the browser. Rendering markdown only puts the img element on the page. It's up to the browser and its caching to determine whether the file should be redownloaded or not. Refreshing the page may be required, but restarting the kernel never will be. I'm not sure if there is a way to put a reference to the same image URL on the same page multiple times and have it re-fetch each time. It's possible our cache headers set by the server when requesting the image could accomplish this.
I also ran into this issue as I prefer to render matplotlib images and import them into the notebook with <img src="..."> tags.
There is a solution to adjust the caching. In this case the server is set-up to prevent caching for files with arguments to their http request.
In notebook.files.handlers.py you can make the edit:
if self.get_argument("download", False):
self.set_header('Content-Disposition','attachment; filename="%s"' % name)
if "?" in name:
self.set_header("Cache-Control", "no-cache; no-store")
# get mimetype from filename
now access images which you want to force refreshing with
as  or <img src="image.png?arg">
and the webserver will prevent caching.
In general, the browser should prevent caching if you vary the arguments anyway, but I was finding that firefox at least would still cache them, so I added this fix. I was actually going to submit my own bug report to suggest the addition, but here is a good place.
If this is a reasonable change, It would be nice to insert it to the project.
Since you made the change have you noticed any adverse affects in it or other workbooks? Refreshing the webpage via the browser appears to work for me without needing to terminate the kernel but maybe it would be nice to be able to indicate cells as not to cache if that were possible
I have not noticed any issues so far, though I'll note that I am using newest Firefox and these issues tend to occur in less compliant browsers.
I agree that some granularity would be nice. Ideally you could hook it into the "display" functions to have action not just for the json sent to the clients but for the server as well. There would have to be additional metadata in the stored format for this to work and so would be a pretty nontrivial change.
I suspect actually that having the image loaded by a json scriptlet that injects the image into the DOM would work as well, (and give some options for bypassing local caching), but that was beyond the scope of this quick fix.
On Fri, Jun 10, 2016 at 6:35 AM, mobcdi [email protected] wrote:
Since you made the change have you noticed any adverse affects in it or other workbooks? Refreshing the webpage via the browser appears to work for me without needing to terminate the kernel but maybe it would be nice to be able to indicate cells as not to cache if that were possible
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jupyter/notebook/issues/1369#issuecomment-225149799, or mute the thread https://github.com/notifications/unsubscribe/AAZQ850PJKtz-dRVjAc5bD8hCaO7yALjks5qKT3mgaJpZM4IKHkp .
Any plans to implement cache busting in the classic notebook? Ping @gnestor? As @ian-r-rose pointed out in JuliaPlots/Plots.jl#1447, it makes sense for it to be the responsibility of the frontend, and is being done in Jupyter Lab.
I noticed the same issue when doing something along the lines of
display(SVG(data=buffer.get_value()))
I think at least in the case of IPython's own display methods, there should be an option to prevent caching.
AFAIK, the browser is caching the image (not ipython or anything Jupyter-related). The trick for invalidating an image cache is to add a query string to the URL:
<img src="image.png?modified=12345678" />
Source: https://stackoverflow.com/a/321871/2217533
I haven't tested this using IPython.display.SVG or any other ipython display functions...
Is there a planned fix on this? It's causing problems for Julia users: https://github.com/JuliaPlots/Plots.jl/pull/1448
I just commented at https://github.com/JuliaPlots/Plots.jl/issues/1447#issuecomment-454707443
Sorry if this is stale bug; I just ran into it.
Shouldn't it be possible to modify the Jupyter Markdown display to automatically put a nonsense parameter into the URL and update that parameter if and only if the cell is excuted? That is,  is quietly transformed to .
What am I misunderstanding?
Shouldn't it be possible to modify the Jupyter Markdown display to automatically put a nonsense parameter into the URL and update that parameter if and only if the cell is excuted? That is,
is quietly transformed to.What am I misunderstanding?
I would like to join this old, but very relevant (to me) conversation. I think @merriam is right on the money, and this should even be the default behaviour. However, I suspect that since most people here are python people, it does not resonate.
I use jupyter notebook to teach multiple things, but never python itself. So inserting a python call in the middle of a, say, octave notebook seems like a distraction:
from IPython.display import display, Image
display(Image('image.png'))
therefore I much prefer to include images via markdown.
The problem is bypassing the browser cache, and the trick of augmenting the file name with a variable string would be the best and simplest to implement.
I see three candidates: a timestamp, a random number, or the cell index. What facilities are available in a mardown cell to find out any of the three?
I tried this
<img src="image.png?<?php echo time(); ?>">
but php does not seem to work inside simple markup.
Is there a way to get at the cell index number (which changes after every cell re-execution, so would change on every cell reload)?
Failing that, is there a way to generate a random number?
I'm also experiencing the same problem when using Jupyter in VSCode - I need to close and reopen the ipynb file to refresh it. Is there a simpler way to do this?