nuxt / nuxt/image

Images with `display: none` are still being fetched

Open
#1,035 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug enhancement performance
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

  1. Doing a v-if and listening to the screen size in JavaScript. That would not be good for initial loading and SEO.
  2. Adding loading="lazy" which will also not be good since the images are in the first loading viewport (in my case)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.