I am reading and taking notes on the HTML specifications for 100 days as part of #The100DayProject. Read the initial intent/backstory. I am a Microsoft employee but all opinions, comments, etc on this site are my own. I do not speak on behalf of my employer, and thus no comments should be taken as representative of Microsoft's official opinion of the spec. Subsections not listed below were read without comment.
Currently reading 4.7 Embedded content
UAs = User agents = Browsers, etc.
img element, contd.
Current pixel density:
- Initially undefined.
- “When an img element has a current pixel density that is not 1.0, the element's image data must be treated as if its resolution, in device pixels per CSS pixels, was the current pixel density.” So a 200px square image on a 2x screen is interpreted to be a 100px square image (hence, a blurry image if you choose to show it scaled to 200px square).
Didn’t know that the Document object stores a list of available images. UAs can copy these listed images to other documents (or remove). This would effectively be image caching so that an image doesn’t need to be fetched every time you encounter it.
There’s a looooong algorithm for update an
image element’s image data. Interestingly, everything gets reset when you do this: the
img element gets put back in the unavailable state, and all its data is wiped. So switching out the
src may not be as performant as you might think (anecdotally, it can feel noticeable to the end user that “work” is being done, a flash or something similar).
- UAs can’t support non-image files in the
imgelement. But…the spec doesn’t define what image types are. Alright, cool. As an aside there’s definitely some proprietary stuff going on with image file types.
- They also can’t run executable code in an image resource. Security!
- If the
srcfile is multi-page, like a PDF, only the first page is shown. I didn’t know you could use a PDF file in an
imgelement…but depending on how big the file is that seems wasteful from a weight perspective.