How would you serve appropriately-sized images so a phone doesn't download a huge desktop image?

technical-conceptual · Junior level · software-engineering

What the interviewer is really asking

Tests whether the candidate knows the responsive-images toolkit — srcset, sizes, and the picture element — and why it matters for mobile performance.

What to say

What to avoid

Example answers

Strong: I'd give the <img> a srcset listing the photo at 480w, 800w, and 1600w plus a sizes attribute saying it's 100vw on phones and 50vw on desktop. The browser then downloads the smallest file that still looks sharp for that screen and pixel density, so a phone never pulls the 1600px version.

Weak: I just set a max-width of 100% in CSS so the image scales down to fit — that makes it responsive.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.