Do I use , <>, >

后端 未结 15 2130
借酒劲吻你
借酒劲吻你 2020-11-22 06:10

Should I use , , or for loading SVG files into a page in a way similar to loading a jpg
15条回答
  •  猫巷女王i
    2020-11-22 07:10

    Use srcset

    Most current browsers today support the srcset attribute, which allows specifying different images to different users. For example, you can use it for 1x and 2x pixel density, and the browser will select the correct file.

    In this case, if you specify an SVG in the srcset and the browser doesn't support it, it'll fallback on the src.

    My logo
    

    This method has several benefits over other solutions:

    1. It's not relying on any weird hacks or scripts
    2. It's simple
    3. You can still include alt text
    4. Browsers that support srcset should know how to handle it so that it only downloads the file it needs.

提交回复
热议问题