Images with `display: none` are still being fetched
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 331
- Avg merge
- 19h 52m
- Merged PRs (30d)
- 9
Description
I have some images that are only specifically displayed on mobile/desktop. With the regular <img /> tag, setting them to display: none will not load any images. But with <NuxtImg />, the image also gets fetched, even though it's never displayed. This costs some unnecessary bandwith for mobile users.
Reproduction
https://stackblitz.com/edit/github-p3cr3h?file=nuxt.config.ts,app.vue
Workarounds
- Doing a
v-ifand listening to the screen size in JavaScript. That would not be good for initial loading and SEO. - Adding
loading="lazy"which will also not be good since the images are in the first loading viewport (in my case)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open the StackBlitz reproduction and inspect nuxt.config.ts and app.vue, starting with how NuxtImg handles images hidden by display: none. Confirm the behavior across the mobile and desktop cases, then verify that hidden images are no longer fetched without relying on v-if or loading="lazy".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nuxt, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100