From 78d0ea6fa5f6e72b28233e292c9e7f9c91f1c257 Mon Sep 17 00:00:00 2001 From: Johnpaul Chiwetelu <49923152+Myestery@users.noreply.github.com> Date: Thu, 18 Sep 2025 19:20:19 +0100 Subject: [PATCH] LazyImage on Safari (#5626) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This pull request improves the lazy loading behavior and caching strategy for images in the `LazyImage.vue` component. The most significant changes are focused on optimizing image rendering and resource management, as well as improving code clarity. **Lazy loading behavior improvements:** * Changed the `` element to render only when `cachedSrc` is available, ensuring that images are not displayed before they are ready. * Updated watchers in `LazyImage.vue` to use clearer variable names (`shouldLoadVal` instead of `shouldLoad`) for better readability and maintainability. [[1]](diffhunk://#diff-3a1bfa7eb8cb26b04bea73f7b4b4e3c01e9d20a7eba6c3738fb47f96da1a7c95L80-R81) [[2]](diffhunk://#diff-3a1bfa7eb8cb26b04bea73f7b4b4e3c01e9d20a7eba6c3738fb47f96da1a7c95L96-R96) **Caching strategy enhancement:** * Modified the `fetch` call in `mediaCacheService.ts` to use `{ cache: 'force-cache' }`, which leverages the browser's cache more aggressively when loading media, potentially improving performance and reducing network requests. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5626-LazyImage-on-Safari-2716d73d365081eeb1d3c2a96be4d408) by [Unito](https://www.unito.io) --- src/components/common/LazyImage.vue | 8 ++++---- src/services/mediaCacheService.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/common/LazyImage.vue b/src/components/common/LazyImage.vue index 79c7320f6..36aaa8a2b 100644 --- a/src/components/common/LazyImage.vue +++ b/src/components/common/LazyImage.vue @@ -10,7 +10,7 @@ class="absolute inset-0" /> isIntersecting.value) watch( shouldLoad, - async (shouldLoad) => { - if (shouldLoad && src && !cachedSrc.value && !hasError.value) { + async (shouldLoadVal) => { + if (shouldLoadVal && src && !cachedSrc.value && !hasError.value) { try { const cachedMedia = await getCachedMedia(src) if (cachedMedia.error) { @@ -93,7 +93,7 @@ watch( console.warn('Failed to load cached media:', error) cachedSrc.value = src } - } else if (!shouldLoad) { + } else if (!shouldLoadVal) { if (cachedSrc.value?.startsWith('blob:')) { releaseUrl(src) } diff --git a/src/services/mediaCacheService.ts b/src/services/mediaCacheService.ts index 65f87a43c..b2e24c29e 100644 --- a/src/services/mediaCacheService.ts +++ b/src/services/mediaCacheService.ts @@ -113,7 +113,7 @@ class MediaCacheService { try { // Fetch the media - const response = await fetch(src) + const response = await fetch(src, { cache: 'force-cache' }) if (!response.ok) { throw new Error(`Failed to fetch: ${response.status}`) }