impr: optimize image delivery
This commit is contained in:
5 files changed
+82
-50
No files matched your search
@@ -40,27 +40,38 @@
|
||||
scale-[1.2] opacity-50"
|
||||
/>
|
||||
<picture class="max-h-[inherit]">
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 512)}
|
||||
media="(max-width: 256px)"
|
||||
/>
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 1024)}
|
||||
media="(max-width: 512px)"
|
||||
/>
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 1536)}
|
||||
media="(max-width: 1024px)"
|
||||
/>
|
||||
{#each ['webp'] as format}
|
||||
<source
|
||||
srcset="{bestImageURL(
|
||||
post,
|
||||
false,
|
||||
512,
|
||||
format as 'avif' | 'webp',
|
||||
)} 512w, {bestImageURL(
|
||||
post,
|
||||
false,
|
||||
768,
|
||||
format as 'avif' | 'webp',
|
||||
)} 768w, {bestImageURL(
|
||||
post,
|
||||
false,
|
||||
1024,
|
||||
format as 'avif' | 'webp',
|
||||
)} 1024w"
|
||||
media="(min-width: 0px)"
|
||||
type="image/{format}"
|
||||
/>
|
||||
{/each}
|
||||
<img
|
||||
src={bestImageURL(post, false, -1)}
|
||||
src={bestImageURL(post, false, -1, null)}
|
||||
loading="lazy"
|
||||
class="max-h-[inherit] max-w-full h-auto z-30
|
||||
transition-opacity duration-500 object-contain mx-auto
|
||||
{imageLoaded === false ? 'opacity-0' : 'opacity-100'}"
|
||||
class={[
|
||||
'max-h-[inherit] max-w-full h-auto z-30 transition-opacity duration-500 object-contain mx-auto',
|
||||
imageLoaded === false ? 'opacity-0' : 'opacity-100',
|
||||
blur && 'blur-3xl',
|
||||
]}
|
||||
width={512}
|
||||
height={300}
|
||||
class:blur-[64px]={blur}
|
||||
alt={post.alt_text ?? ''}
|
||||
onload={() => (imageLoaded = true)}
|
||||
/>
|
||||
|
||||
@@ -46,7 +46,6 @@
|
||||
url={post.url}
|
||||
thumbnail_url={post.thumbnail_url}
|
||||
nsfw={post.nsfw}
|
||||
embed_description={post.embed_description}
|
||||
embed_title={post.embed_title}
|
||||
{view}
|
||||
/>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
bestImageURL,
|
||||
optimizeImageURL,
|
||||
postLink,
|
||||
type MediaType,
|
||||
} from '$lib/components/lemmy/post/helpers.js'
|
||||
@@ -70,10 +69,34 @@
|
||||
class="cursor-pointer"
|
||||
>
|
||||
{#if post.thumbnail_url || isImage(post.url)}
|
||||
{@const thumbnail = post.thumbnail_url != undefined && !isImage(post.url)}
|
||||
<div class="relative overflow-hidden rounded-xl">
|
||||
<picture>
|
||||
<!--I would add AVIF, but lemmy.world's AVIF is broken as of currently-->
|
||||
{#each ['webp'] as format}
|
||||
<source
|
||||
srcset="{bestImageURL(
|
||||
post,
|
||||
thumbnail,
|
||||
128,
|
||||
format as 'avif' | 'webp',
|
||||
)} 1x, {bestImageURL(
|
||||
post,
|
||||
thumbnail,
|
||||
256,
|
||||
format as 'avif' | 'webp',
|
||||
)} 2x, {bestImageURL(
|
||||
post,
|
||||
thumbnail,
|
||||
512,
|
||||
format as 'avif' | 'webp',
|
||||
)} 3x"
|
||||
media="(min-width: 0px)"
|
||||
type="image/{format}"
|
||||
/>
|
||||
{/each}
|
||||
<img
|
||||
src={optimizeImageURL(post.thumbnail_url || post.url || '', 256)}
|
||||
src={bestImageURL(post, thumbnail, -1, null)}
|
||||
loading="lazy"
|
||||
class={[
|
||||
'object-cover relative overflow-hidden bg-slate-100 dark:bg-zinc-800 rounded-xl transition-colors',
|
||||
|
||||
Reference in new issue
Block a user