Multiple base64 files in one

后端 未结 7 955
不知归路
不知归路 2021-01-16 08:29

Can you combine these 2 images into one external file on this JS fiddle and link to them as images?

Something like



        
7条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-16 08:41

    It is not possible in pure HTML within the data URI specification. (http://en.wikipedia.org/wiki/Data_URI_scheme)

    It is possible to use JavaScript to grab only a substring of the base64 data/document and set that as the img's src attribute, as the linked answer proposes.

    I'm just not sure that it's worth the trouble to do it this way, it seems rather complicated for maybe a very small gain in loading time.


    if you want to use it, one way to do it could be this (simple draft, no error handling, no fancy functions): in your HTML document:

    
    

    in your base64file.js:

    allImages = 'abc... <- the base64 code for the first image
                 $ <- split indicator that is not a part of the base64 character set
                cba.... <- the base64 code for the second image
                ';
    

提交回复
热议问题