LF-5230 Make farm note images available offline#4116
Merged
SayakaOno merged 3 commits intointegrationfrom Apr 13, 2026
Merged
Conversation
kathyavini
commented
Apr 10, 2026
| } | ||
| } else { | ||
| const url = new URL(fileUrl); | ||
| const url = new URL(fileUrl); |
Collaborator
Author
There was a problem hiding this comment.
The change to the if/else brackets made this look like a much bigger diff than it actually is... changes were:
Removed this:
if (import.meta.env.VITE_ENV === 'development') {
if (subscribed) {
setMediaUrl(fileUrl);
}
} else {instead did this:
if (import.meta.env.VITE_ENV !== 'development') {
url.hostname = 'images.litefarm.workers.dev';
}so that fetch() is used for both dev as well as in beta/prod, so the service worker can intercept the request and cache it. This was necessary to see the farm-note-image cache created in development.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This adds runtime caching of images to the Farm Notes feature in a new dedicated cache
farm-notes-images. To keep this cache from accumulating stale images and growing out of control, theworkbox-expirationplugin was used, and the cache images set to:purgeOnQuotaError<-- documentation has nothing to say on what this is exactly, but Claude saysSo that sounds like exactly what we want -- these images are the least important part of our cache compared to the request queue and
workbox-precacheapplication code.With the imaginary compressed images, I was seeing quite small image files, and 50 entries is unlikely to be more than 3-5MB of total data 🙂 I'll add new cache-checking code below
Jira link: https://lite-farm.atlassian.net/browse/LF-5230
Type of change
How Has This Been Tested?
I ran
pnpm buildandpnpm previewto create the cache onlocalhost:4173. As usual you can then go offline and reload to see the images subsequently served from cache.Here is also new cache-inspecting code for the browser console which tallies per cache:
With that I was finding a very modest cache size for my note images! 🎉
Checklist:
pnpm i18nto help with this)