Skip to content

Instantly share code, notes, and snippets.

@tennisonchan
Last active June 17, 2018 09:28
Show Gist options
  • Save tennisonchan/5682cca60f74ec84f7ea8b292ceb3274 to your computer and use it in GitHub Desktop.
Save tennisonchan/5682cca60f74ec84f7ea8b292ceb3274 to your computer and use it in GitHub Desktop.

Image Optimization: Beyond The Basics

https://www.youtube.com/watch?v=hQZ7Xg7q7zw

Images are by far the greatest bottleneck to performance on the web, and with the average web page size now about 2.5MB large—images taking up 65% of that.

WebP is a new image format which is smallest and provdes either lossless or lossy compression.

<img
  src="dog-800w.jpg" alt="A dog"
  srcset="
  dog-320w.jpg 320w,
  dog-400w.jpg 400w,
  dog-800w.jpg 800w"
  size="
  (max-width: 320px) 280px,
  (max-width: 480px) 440px,
  800px"
/>

Shader Playground

https://www.shadertoy.com/

Cloud Service

Optimizer

Image Liftcycle

  1. Downloading Image
  2. Reading header
  3. Decoding image
  4. VRAM upload
  5. Composition
  6. Display
  • PNG magic number: 89 50 4E 47

Blur Up Technique

Scale down the image to a fraction of the original size, then applying a blur filter for the transition.

https://css-tricks.com/the-blur-up-technique-for-loading-background-images/

Histogram Scope Reduction

Turn the image into black and white to reduce the size

CSS: mix-blend-mode

Not support on IE edge yet.

.color::after {
  background: linear-gradient(to left, red, blue);
  z-index: -1;
}
.color img {
  mix-blend-mode: luminosity
}

CSSgram

A lightweight lib to recreate Instagram filters. https://una.im/CSSgram/

Duo Tone

Darken highlight + Ligten shadow

img {
  --duo-highlight: #ff3ebf;
  --duo-shadow: #4000ff;
}

Constrast Swap Technique

  • Reduce size by around 20%
  • Small impact for repainting on browser
  1. Improve compression
  2. Correct via shader multiply
img {
  filter: contrast(100%);
}

Never use gifs

Never use gif on frontend. Use mp4 or webm instead.

<video>
  <source
    src="src/video.mp4"
    type="video.mp4" />
  <source
    src="src/video.webm"
    type="video.webm" />
</video>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment