Does mousemove check a good way to determine if assets should be loaded?

So, I have a web application designed to view photos.

When you click on a thumbnail application

  • requests an image object
  • injects it into the DOM as an IMG tag
  • and provides another

(MooTools Asset.image , inject and dispose ).

If they click on an already downloaded image, I will simply add it again, since dispose saves it.

Users look at images for an average of 12 seconds (according to my statistics), which is enough time to download a few more.

So my question is again, slightly paraphrased:

Good or bad practice is to determine whether other assets should be loaded in the background based on their mouse movement?

So, if the mouse does not move, load the next few assets. If it starts moving, stop and wait for the mouse to stop (and you will have a short interval before loading again, for example, 1 or 2 seconds).

It seems like a good idea to me, but it seems to me that there are some side effects that I don't think about.

Gracias.

+4
source share
3 answers

To answer your question directly, I don’t think there will be a problem, except that checking the mouse movement will have certain overhead. I would measure performance on a slow machine as soon as you are done to make sure this is a problem.

+2
source

You can make your buttons back and forth large areas (white / transparent backgrounds) and check the hover over these backgrounds and load images when the cursor is in these areas. Basically upload an image right before clicking a button.

+2
source

There is an entry point for these background tasks: requestidlecallback

-1
source

Source: https://habr.com/ru/post/1286387/


All Articles