Skip to content

Commit

Permalink
Add WebP variants for asset icons
Browse files Browse the repository at this point in the history
For browsers that support WebP, this reduces the size of asset images
by ~88%.  Other browsers will fall back to PNG images.

Change-Id: I47e973bf9df0db844f8a2dedd2a9a4ff56af4203
  • Loading branch information
joeyparrish committed May 13, 2019
1 parent bd787fd commit 1461692
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion demo/asset_card.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,25 @@ class AssetCard {
titleDiv.appendChild(titleText);

if (asset.iconUri) {
const picture = document.createElement('picture');

const webpSource = document.createElement('source');
webpSource.srcset = asset.iconUri.replace(/.png$/, '.webp');
webpSource.type = 'image/webp';

const pngSource = document.createElement('source');
pngSource.srcset = asset.iconUri;
pngSource.type = 'image/png';

const img = document.createElement('img');
img.src = asset.iconUri;
img.alt = ''; // Not necessary to understand the page
this.card_.appendChild(img);

picture.appendChild(webpSource);
picture.appendChild(pngSource);
picture.appendChild(img);

this.card_.appendChild(picture);
}

if (asset.description && isFeatured) {
Expand Down

0 comments on commit 1461692

Please sign in to comment.