找到你要的答案

Q:direct manipulation of image cache

Q:直接操作图像缓存

I would like to directly manipulate the image cache as follows

  1. create image data using canvas and store it in an Image object
  2. somehow associate the Image object with a url such as "www.foo.com/bar.png"
  3. setting the .src of any future Images to that url will use the cached version

I don't think this is possible but does anyone have any suggestions?

The closest I can think of is setting an attribute such as data-src instead and using a MutationObserver to intercept my fake url and set the image src that way.

我想直接操作图像缓存如下

  1. create image data using canvas and store it in an Image object
  2. somehow associate the Image object with a url such as "www.foo.com/bar.png"
  3. setting the .src of any future Images to that url will use the cached version

我不认为这是可能的,但是有人有什么建议吗?

我能想到的最接近的是设置一个属性如数据SRC代替使用MutationObserver拦截我的假网址,这样图像的src。

javascript  html5