perf: add lazy loading and reduce memory footprint
- Add loading="lazy" decoding="async" to images in AlbumCard, ArtistDetailView - Convert AlbumCard hover from JS state to CSS :hover (fewer re-renders) - Reduce IntersectionObserver thresholds from 4 to 1 in ArtistDetailView - Reduce default audio cache from 500MB to 200MB
This commit is contained in:
1 parent
3e8fe0771a
commit
dbc004eed7
3 files changed
+26
-17
No files matched your search
@@ -12,7 +12,6 @@
|
||||
|
||||
let { artwork, title, artist, quality, size = 'standard', onclick }: Props = $props();
|
||||
|
||||
let isHovered = $state(false);
|
||||
let imageError = $state(false);
|
||||
const cardSize = $derived(size === 'large' ? 180 : 162);
|
||||
|
||||
@@ -24,8 +23,6 @@
|
||||
<div
|
||||
class="album-card"
|
||||
style="width: {cardSize}px"
|
||||
onmouseenter={() => (isHovered = true)}
|
||||
onmouseleave={() => (isHovered = false)}
|
||||
onclick={onclick}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
@@ -34,24 +31,22 @@
|
||||
<!-- Artwork Container -->
|
||||
<div
|
||||
class="artwork-container"
|
||||
style="width: {cardSize}px; height: {cardSize}px; transform: scale({isHovered ? 1.02 : 1})"
|
||||
style="width: {cardSize}px; height: {cardSize}px"
|
||||
>
|
||||
{#if imageError || !artwork}
|
||||
<div class="artwork-placeholder">
|
||||
<Disc3 size={48} />
|
||||
</div>
|
||||
{:else}
|
||||
<img src={artwork} alt={title} onerror={handleImageError} />
|
||||
<img src={artwork} alt={title} loading="lazy" decoding="async" onerror={handleImageError} />
|
||||
{/if}
|
||||
|
||||
<!-- Play Button Overlay -->
|
||||
{#if isHovered}
|
||||
<div class="play-overlay">
|
||||
<div class="play-button">
|
||||
<Play size={24} fill="white" color="white" />
|
||||
</div>
|
||||
<!-- Play Button Overlay (CSS-only hover) -->
|
||||
<div class="play-overlay">
|
||||
<div class="play-button">
|
||||
<Play size={24} fill="white" color="white" />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Text Info -->
|
||||
@@ -79,6 +74,10 @@
|
||||
transition: transform 150ms ease-out;
|
||||
}
|
||||
|
||||
.album-card:hover .artwork-container {
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
.artwork-container img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
@@ -113,6 +112,12 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
opacity: 0;
|
||||
transition: opacity 150ms ease;
|
||||
}
|
||||
|
||||
.album-card:hover .play-overlay {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.play-button {
|
||||
|
||||
@@ -330,7 +330,7 @@
|
||||
{
|
||||
root: artistDetailEl,
|
||||
rootMargin: '-20% 0px -60% 0px',
|
||||
threshold: [0, 0.2, 0.5, 1]
|
||||
threshold: [0.5] // Single threshold for better performance
|
||||
}
|
||||
);
|
||||
|
||||
@@ -363,6 +363,8 @@
|
||||
src={artist.image}
|
||||
alt={artist.name}
|
||||
class="artist-image"
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
onerror={handleImageError}
|
||||
/>
|
||||
{/if}
|
||||
@@ -434,6 +436,8 @@
|
||||
src={getSimilarArtistImage(similar)}
|
||||
alt={similar.name}
|
||||
class="similar-avatar"
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
onerror={() => handleSimilarArtistImageError(similar.id)}
|
||||
/>
|
||||
{/if}
|
||||
@@ -494,7 +498,7 @@
|
||||
<div class="track-number">{index + 1}</div>
|
||||
<div class="track-artwork">
|
||||
{#if track.album?.image?.thumbnail || track.album?.image?.small}
|
||||
<img src={track.album?.image?.thumbnail || track.album?.image?.small} alt={track.title} />
|
||||
<img src={track.album?.image?.thumbnail || track.album?.image?.small} alt={track.title} loading="lazy" decoding="async" />
|
||||
{:else}
|
||||
<div class="track-artwork-placeholder">
|
||||
<Music size={16} />
|
||||
@@ -632,7 +636,7 @@
|
||||
>
|
||||
<div class="playlist-artwork">
|
||||
{#if playlist.artwork}
|
||||
<img src={playlist.artwork} alt={playlist.title} />
|
||||
<img src={playlist.artwork} alt={playlist.title} loading="lazy" decoding="async" />
|
||||
{:else}
|
||||
<div class="playlist-artwork-placeholder">
|
||||
<Music size={18} />
|
||||
|
||||
Reference in new issue
Block a user