search

Home  >  Q&A  >  body text

Will the server send more than 1 image to the <picture> tag and fall back?

I'm curious about image tags implemented like this.

<picture>
  <source srcset="path/img.webp" type="image/webp" />
  <img src="path/img.jpg" alt="image" />
</picture>

For the client, I understand that if the browser can handle webp, it will display the webp image sent from the server; otherwise, it will display the jpg image also sent from the server.

I want to know if the server needs to send both images to the client or if the server only sends one image that the client can handle since my goal is server bandwidth optimization.

P粉674876385P粉674876385231 days ago463

reply all(1)I'll reply

  • P粉556159786

    P粉5561597862024-04-04 00:27:03

    It takes a "lazy" approach. It will not request the file specified in the source element until the source element is "available".

    "Available" may mean any of the following:

    • Browser supports this file type
    • Media Query Fulfilled

    Take Demo as an example https://www.w3schools.com/tags/tag_picture.asp" rel="nofollow noreferrer">W3Schools:
    (Copy of presentation below)

    
    
    
    
      
    
    
    
      

    The picture element

    Resize the browser window to load different images.

    Flowers

    reply
    0
  • Cancelreply