Shrink an elephant into a fly

Vadim Makeev, HTML Academy

Shrink
an elephant
into a fly

An elephan with wings
HTML Academy logo
Fronteers
How come, Fronteers?

Content

  • Page contents
  • Created after
  • Could be copied, saved
  • Separated from code
  • What user needs

Interface

  • Decoration, design
  • Like code, but not exactly
  • Created with code
  • Lives with code
  • Sometimes code
SVG vs PNG

Formats

Colors Transparency Animation
GIF 256 Yes Yes
PNG 256 or more Yes, alpha Yes, but no
JPEG A lot No No
SVG A lot Yes Yes
WebP 256 or more Yes, alpha Yes
HEIC A lot Yes, alpha Yes
List of heavy GIFs

GIF is a genre,
not a format anymore.

Video

            <video autoplay loop muted>
                <source type="video/webm" src="bolt.webm">
                <source type="video/mp4" src="bolt.mp4">
            </video>
        
            $ ffmpeg -i bolt.gif -movflags faststart -pix_fmt yuv420p -crf 0 bolt.mp4
        

GIF

Animated hourglass Hourglass animation frames
Deadpool dressed up as Bob Ross

CSS graphics

                .burger {
                    position: relative;
                    width: 12px;
                    height: 10px;
                }
            
                .burger__line {
                    position: absolute;
                    left: 0;
                    width: 12px;
                    height: 2px;
                    background-color: #4b86c2;
                }
            

CSS graphics, better

                .burger {
                    width: 12px; height: 10px;
                    background-image: repeating-linear-gradient(
                        #4b86c2, #4b86c2 2px,
                        #fff 2px, #fff 4px
                    );
                }
            

Manual SVG

            <svg width="120" viewBox="0 0 12 10" fill="#4b86c2">
                <rect width="12" height="2" x="0" y="0"/>
                <rect width="12" height="2" x="0" y="4"/>
                <rect width="12" height="2" x="0" y="8"/>
            </svg>
        

Canvas

Bored Fry

CSS Paint API

            div {
                --burger-color: #4b86c2;
                background-image: url('burger.png');
                background-image: paint(burger);
            }
        
            CSS.paintWorklet.addModule('burger.js');
        

CSS Paint API

            class Shape {
                static get inputProperties() {
                    return ['--burger-color'];
                }
                paint(context, geometry, properties) {  }
            }
            registerPaint('burger', Shape);
        

CSS Paint API

            const color = properties.get(
                '--burger-color'
            );
            context.fillStyle = color;
            context.fillRect(0, 0, 120, 20);
            context.fillRect(0, 40, 120, 20);
            context.fillRect(0, 80, 120, 20);
        

CSS Paint API

            div:hover {
                --burger-color: #32b332;
            }
        

CSS Paint API

Fry is eager to pay

Export

PNG PNG 8 JPG SVG
Photoshop 852 155 3596 130
Affinity 1555 856 10793 602
Sketch 5639 3836 525
Figma 2179 7797 153
Hands 111 111 1144 98
  1. Export wherever you want
  2. Compress with tools
Squoosh
SVGOMG

Content

            <img src="cat.jpg" alt="Red cat">
        

Interface

            button {
                background-image: url(icon.png);
            }
        

Content?

            div.picture {
                background-image: url(picture.png);
                background-size: cover;
            }
        

Content!

            img, video {
                object-fit: cover;
                object-position: 25% 0;
            }
        

Good interface
is like a progress bar.

DVD

Base64

            button {
                background-image: url('data:image/png;base64,iVBORw0K
        EUgAAAgAAAAIACAYAAAD0eNT6AAAACXBIWXMAAA7EAAAOxAGV
        AAgyAAAQJABAIAgAwAAQQYAAIIMAAAEGQAACDIAABBkAAAgyA
        MAAAEGQAACDIAABBkAAAgyAAAQJABAIAgAwAAQQYAAIIMAAAE
        ABBkAAAgyAAAQJABLJBGFFAIAgAwAAQQYAAIIMAAAEGQA…');
            }
        

URL encoding

            button {
                background-image: url('data:image/svg+xml,%3Csvg xmlns
        ='http://www.w3.org/2000/svg' viewBox='0 0 12 10'
        fill='%234b86c2'%3E%3Crect width='12' height='2'
        x='0' y='0'/%3E%3Crect width='12' height='2' x='0'
        y='4'/%3E%3Crect width='12' height='2' x='0' y…');
            }
        
  1. External resources could be cached
  2. Critical resources needs to stay lightweight

Links

@pepelsbey_

sokr.me/eif/en