hzdg / react-imageloader

A React component for wrangling image loading

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

plugin appears to disable browser caching

mgenev opened this issue · comments

Someone opened a PR using this plugin on a project I run and it appears that after this plugin is used, the default React and browser behavior of caching the already requested images and instantly displaying them is disabled and the images are re-requested every time I go to this route. Is there a way to preserve this caching so the placeholder shows just once and from then on the cache is used to display the images instantly like React normally does?

Hi @mgenev, this component doesn't fundamentally do anything to disable browser caching. In fact, it loads images off DOM, and then inserts the same src into the DOM after that load completes, so the browser actually has to cache the loaded image in order for the component to behave correctly!

It may be that you're seeing the image load twice because browser caching is already disabled, and this component expects it to be enabled in order to avoid a second load.

If this explanation doesn't seem correct to you, can you provide an example or test case that demonstrates the behavior you're seeing?

FWIW, I do think that loading off-DOM was probably a mistake, and that a future version of this component should always load in-DOM, and not rely on browser caching to work at all.