Javascript if (document.images)

I am analyzing another person's JavaScript code and found this condition

if (document.images) 

I use other sites that are used to check if the browser supports dynamic images. Something like when we overlay a mouse on an image, another image is loading. This is like very old JavaScript. Does it make sense to use it now? Does this condition have another purpose?

+6
source share
3 answers

If the browser supports image arrays, this condition returns true. Internet Explorer> 3 supports this :) check out this article http://www.quirksmode.org/js/support.html

And yes, this is very old js, no need to check it now

+3
source

Preloading images is usually where you find the code that you describe. Although this is not so problematic in modern browsers (they are much more asynchronous and can load several images at once, first find out what is on the screen and load them). However, deleting this file may slow down the application you are working on.

Literature:

+1
source

If you really do not need to configure such old browsers, you can mark this check as obsolete additional code and assume that all major browsers support image preloading (and they actually do), thus have a document.images object.

The document.images object is an array of uploaded images in the current document, and you can use it to add images that will almost certainly be uploaded (for example, images with the mouse) later to achieve a smoother effect.

Validation by this condition ensures that the browser has a document.images object.

By the way, this is not the best method for designing the effect that they manage, unless you really need to do this, because CSS allows you to get better (faster and less) results.

+1
source

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


All Articles