Detect webpsupport on start-up
This commit is contained in:
parent
e63df156d9
commit
98b6310b6f
|
@ -54,6 +54,13 @@
|
||||||
let totalPages = 1;
|
let totalPages = 1;
|
||||||
let ready;
|
let ready;
|
||||||
|
|
||||||
|
let imgType = '.jpg';
|
||||||
|
// detect WebP support
|
||||||
|
$create('img', {
|
||||||
|
src: 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=',
|
||||||
|
onload: () => (imgType = '.webp'),
|
||||||
|
});
|
||||||
|
|
||||||
const $class = sel => (sel instanceof Node ? sel : $(sel)).classList;
|
const $class = sel => (sel instanceof Node ? sel : $(sel)).classList;
|
||||||
const show = sel => $class(sel).remove('hidden');
|
const show = sel => $class(sel).remove('hidden');
|
||||||
const hide = sel => $class(sel).add('hidden');
|
const hide = sel => $class(sel).add('hidden');
|
||||||
|
@ -287,17 +294,11 @@
|
||||||
const elShot = $('.search-result-screenshot-default', entry);
|
const elShot = $('.search-result-screenshot-default', entry);
|
||||||
if (isUsw) {
|
if (isUsw) {
|
||||||
if (/^https?:/i.test(shotName)) {
|
if (/^https?:/i.test(shotName)) {
|
||||||
elShot.src = shotName;
|
if (imgType !== '.jpg') {
|
||||||
// USw has by default a screenshot of the style in webp format.
|
elShot.src = shotName.replace(/\.jpg$/, imgType);
|
||||||
// But for compatability reasons always deliver the jpg format.
|
} else {
|
||||||
// Webp format is more efficient and thus is preffered to be used.
|
elShot.src = shotName;
|
||||||
// When supported.
|
}
|
||||||
const webpElShot = $create('source', {
|
|
||||||
type: 'image/webp',
|
|
||||||
srcset: shotName.replace(/\.jpg$/, '.webp'),
|
|
||||||
});
|
|
||||||
const pictureEl = $('.search-result-screenshot', entry);
|
|
||||||
pictureEl.insertBefore(webpElShot, pictureEl.firstChild);
|
|
||||||
} else {
|
} else {
|
||||||
elShot.src = BLANK_PIXEL;
|
elShot.src = BLANK_PIXEL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user