-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src
attribute of img
inside picture
should be set after img
is appended to picture
to avoid unnecessary requests
#11357
Comments
It seems to happen with vanilla JS: if(document.getElementById("app")) {
// new Vue({ el: '#app'});
}
let picture = document.createElement('picture')
let s1 = document.createElement('source')
s1.media = '(max-width: 900px)'
s1.srcset = "https://www.abc.net.au/radionational/image/6289622-4x3-340x255.png"
let s2 = document.createElement('img')
s2.src = "https://www.solidbackgrounds.com/images/2560x1440/2560x1440-brandeis-blue-solid-color-background.jpg"
s2.alt =''
picture.appendChild(s1)
picture.appendChild(s2)
window.app.innerHTML = 'new'
window.app.appendChild(picture) Could you open a bug report at https://bugs.webkit.org please? |
@posva The issue is how vue is constructing the picture. Creating an img element and setting the src will initiate a request, as expected. To eliminate the redundant img request, the img element must first be added to a picture element before the img.src is set. The following code eliminates the redundant img.src request for views with a width less than 900px
|
src
attribute of img
inside picture
should be set after img
is appended to picture
to avoid unnecessary requests
Good to know the order here matters. Did you find the section on the HTML spec defining this behavior? It's still surprising that Chrome handles it but Safari doesn't |
@posva Any chance you could recommend a fix for this while I wait for a PR? |
This comment has been minimized.
This comment has been minimized.
I'm currently facing the same issue with vue |
Maybe linked to https://bugs.webkit.org/show_bug.cgi?id=190031 |
I'm currently facing the same issue with vue |
Version
2.6.11
Reproduction link
https://codepen.io/CaseJnr/pen/VwvWbPE
Steps to reproduce
Open the codepen link in safari
Inspect the element
Reduce the view width below 900px and refresh the page
You will notice that both the red and blue image is requested.
Comment out the vue instance and refresh the page.
You will notice only the red image is requested (as expected).
What is expected?
Only the required picture resource is requested.
What is actually happening?
Both of the pictures resources are requested, causing redundant downloads.
In Safari, adding a vue instance to any page will cause redundant picture sources to be requested. The picture element will behave correctly if the vue instance is removed.
E.g.
<picture>
<source media="(max-width: 900px)" srcset="small.jpg">
<img src="large.jpg" alt="">
</picture>
By default, only the small.jpg should be requested when the view width is below 900px. However, if a vue instance is added to the page, then both the small.jpg and large.jpg are requested.
The mobile inspector shows the small.jpg request initiator as the page (expected). The large.jpg initiator is actually the vue instance.
The text was updated successfully, but these errors were encountered: