2

I'm writing a pretty simple function to only load the image that is required from a group of four potential images. I have a different version based on size and based on whether or not the browser supports svg; so I don't want to load potentially* four sources for each image - [ * sometimes browsers load images even if display is set to none ].


( note: As I'm writing this question - I'm thinking that maybe I'm going about loading these images the wrong way, but this question remains.)


Anyway, I have img tags with a data-source attribute for each image needed. None of them have a src set at the moment, and I haven't written the js yet to do load the correct one. However, Chrome is loading the image anyway.

When I look at the images when the page loads, the browser has created a src attribute for the first image in each set, and then populated it with the value from data-source for that image.

In other words - first image should show up in the browser like this:

<img data-source="my-image.png">

But instead shows up like this:

<img data-source="my-image.png" src="my-image.png">

Is it in fact Chrome that's doing this? If so, why? (Although I can guess). And is this based upon some principle that would lead a web developer to reasonably expect this to happen (e.g. "That's what data-attributes are for dumbass." ) ?

Community
  • 1
  • 1
dgo
  • 3,755
  • 1
  • 27
  • 39
  • This is not standard behavior for any browser. Are you loading any Javascript files/libraries on the page? – VKK Jan 09 '17 at 21:05
  • Yeah. One of them could be doing it, but it's definitely not expected or desired. – dgo Jan 09 '17 at 21:09
  • I had a similar issue with ***src*** vs ***data-src***. My problem seemed to be fixed by replacing the ***data-src*** with ***data-original-src***. Although this is only a solution if you have control over the generation of the html. – Berty Sep 03 '18 at 08:14

0 Answers0