Skip to content

Commit

Permalink
feat: Lazyload images below the fold (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
evadecker committed Nov 20, 2023
1 parent ed48ce9 commit d84014e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/lib/components/CoverCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
export let original: Album | null = null;
export let cover: Album | null = null;
export let slug: string | null = null;
export let lazy: boolean = false;
let isSkeleton = false;
if (!original && !cover && !slug) isSkeleton = true;
Expand All @@ -19,12 +20,20 @@
<div class="albums">
<div class="album">
{#if original?.album_img}
<img src={original.album_img[1]} alt={`${original.name} album art`} />
<img
src={original.album_img[1]}
alt={`${original.name} album art`}
loading={lazy ? 'lazy' : 'eager'}
/>
{/if}
</div>
<div class="album">
{#if cover?.album_img}
<img src={cover.album_img[1]} alt={`${cover.name} album art`} />
<img
src={cover.album_img[1]}
alt={`${cover.name} album art`}
loading={lazy ? 'lazy' : 'eager'}
/>
{/if}
</div>
</div>
Expand Down
9 changes: 7 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,13 @@
</div>
{:else}
<div class="coversGrid">
{#each value.covers as cover}
<CoverCard original={cover.original} cover={cover.cover} slug={cover.slug} />
{#each value.covers as cover, index}
<CoverCard
original={cover.original}
cover={cover.cover}
slug={cover.slug}
lazy={index > 5}
/>
{/each}
</div>
<div class="pagination">
Expand Down

0 comments on commit d84014e

Please sign in to comment.