question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

g-image loads twice

See original GitHub issue

Description

All g-image load twice, max size and correct viewport size

Screen-2019-05-17_16-16

Steps to reproduce

Thoroughly tested, should be easy to reproduce, or some platform/node version issue

gridsome create gridsome-test
Index.vue <g-image alt="Example image" src="~/assets/pexels-photo-289586.jpeg" width="1920"/>
img {max-width: 100%;}

develop and build versions same result

Expected result

Only load correct size

Actual result

Loads twice

Environment


Libs:
- gridsome version: 0.5.0, 0.6.0, 0.6.1
- @gridsome/cli version: 0.1.0

Browser:
- [ x ] Chrome (desktop) version 74
- [ x ] Firefox version 68
 
For Tooling issues:
- Node version: 11.8
- Platform:  Windows

Others:
Windows 8.1, npm

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dominiquedutracommented, Jun 6, 2019
2reactions
dcastilcommented, Jun 2, 2019

I had a similar issue with an own implementation of lazy-loaded responsive images about half a year ago. But in my case the image was loaded twice only in Safari for some reason. I still hope that the description of my problem and solution can help here.

In my case I left the src and srcset attributes empty at first. When intersecting the image, the state in my Vue image component changed so that both src and srcset were filled with the correct strings. The browser then started downloading the image specified in the src attribute, closely followed by downloading the correct image from the srcset attribute.

I found out that changing the order of the src and srcset attributes in my Vue single file component solved the problem:

<!-- Broken! -->
<img :src="src" :srcset="srcset">

<!-- Working! -->
<img :srcset="srcset" :src="src">

The problem was caused by the browser immediately (literally immediately) firing a request if an <img> source changes while Vue is setting and updating the attributes imperatively under the hood (it can’t set both attributes at once, it has to do it in sequence).

The src attribute was set first, so the browser fired a request to the path specified in there. Afterwards the srcset attribute was set and because the srcset attribute has precedence over src, the image source changed again and the browser fired another request.

So my proposal to the Gridsome team is: Try to make sure that srcset is always set and updated before src in <g-image>. Hopefully that should resolve the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Image somehow loads twice - jquery - Stack Overflow
Is it just me or are there two image tags in this line? $("#content").css({width:newWidth+'px',height:newHeight+'px',margin:'0'}) ...
Read more >
Class GTile — Froggit 2.0a documentation - Cornell CS
This class is a variation on GImage for drawing an image file. ... it will repeat the image twice horizontally and four times...
Read more >
If I use an image twice on the same page, will it increase the ...
Yes but by a very minute difference. The browser will cache the image the first time it loads, so any subsequent display of...
Read more >
Improving a Gridsome website performance - Codegram
Gridsome offers a g-image component that outputs an optimized progressive image. This component loads a very light base64 blurred image by ...
Read more >
1996 Fiddler on the Roof VHS VCR Double Tape Movie Rated G
1996 Fiddler on the Roof VHS VCR Double Tape Movie Rated G image 1. zoom image 2 of 10 ... Loading. Rare find...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found