-2

I am writing an angular app that shows image galleries. I want to eager load the images (from URLs) in "next" gallery before the user clicks "next" so that the next gallery appears to load instantaneously.

I can think of a way to do this by having hidden fields that are made visible but that doesn't seem particularly graceful. Is there a better way?

Dharman
  • 30,962
  • 25
  • 85
  • 135
coffeeeee
  • 129
  • 1
  • 12
  • "I can think of a way to do this" - show us de codes. – Zze Sep 12 '19 at 01:28
  • StackOverflow is not meant to ask for suggestions. You should show the code that you have written, explain any problems with it, then we can help. If we just write an answer, we are likely not addressing your real concern – Ruan Mendes Sep 12 '19 at 01:47

1 Answers1

0

Have an array of image urls and create an image with them.

['image1.jpg', 'image2.jpg'].forEach(url => {
  (new Image()).src = url;
});
Adrian Brand
  • 20,384
  • 4
  • 39
  • 60
  • Not the downvoter, but.... This is one way to do it. It's usually better to wait for the OP to actually post their code so we can know what the difficulty is. This technique is widely known and there are already a lot of answers on StackOverflow that say this. See https://stackoverflow.com/questions/3646036/preloading-images-with-javascript. Even if this is what they were looking for, this question should be closed as a duplicate – Ruan Mendes Sep 12 '19 at 01:51