Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best alternative to the deprecated lowsrc for images?

I would like to use lowsrc with the img tag to show a low resolution image first (and faster) while the larger resolution image loads.

My large resolution images are @800KB and the low res versions @50KB.

Given that lowsrc has been deprecated and many browsers do not apparently support it I am looking for a solution that does the same thing, preferably with as little code as possible.

Is there a good replacement for lowsrc?

like image 904
Bill Noble Avatar asked Nov 28 '14 14:11

Bill Noble


People also ask

What does Lowsrc of image tag do?

The lowsrc property sets or returns a URL to a low-resolution version of an image.

What is the difference between SRC and Srcset?

The srcset attribute allows you to specify a list of image file URLs, along with size descriptions. Yo ualso need to still use the src attribute to identify a “default” image source, to be used in browsers that don't support srcset .

How do I display different image sizes in HTML?

If your image doesn't fit the layout, you can resize it in the HTML. One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels.

What does the lower src attribute of the image tag 2?

The srcset attribute lets the browser select the best option based on its own circumstance — screen size, screen resolution, bandwidth speed. As browsers get smarter, they will include better decision-making about which file to use — and you will never have to worry about it.


1 Answers

<img src="lowres.jpg" onLoad="this.src='highres.jpg'" width="?" height="?">

This alternate version apparently prevents an infinite requesting loop in Firefox (credit to @Ultimater in the comments):

<img src="lowres.jpg" onLoad="this.src='highres.jpg';this.onload=new Function();" width="?" height="?">
like image 107
Jonathan Gray Avatar answered Sep 19 '22 14:09

Jonathan Gray