Will an image with style=“display: none” still be downloaded and cached?

前端 未结 3 1626
逝去的感伤
逝去的感伤 2021-02-19 02:19

I\'m trying to figure out a way to cache the next and previous images in my gallery script ... I\'m wondering if this is a good way to do it. Also, is there any way to manually

3条回答
  •  不知归路
    2021-02-19 02:47

    display: none images will be downloaded and cached on the client. However, JavaScript already has a well-defined way of preloading images:

      var nextImage = new Image();
      nextImage.src = "your-url/newImage.gif";
    

    This will preload an image without displaying it to the user.

提交回复
热议问题