Lists' background images are not cached by clients #1373
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
I'm not 100% sure, but it seems like lists' background images are never cached by clients.
This is specially noticeable for large images while on mobile and using data instead of wifi. They take a long time to load every time the list is opened, or the "Namespace & Lists" page is opened.
This is reproducible on the demo site as well, I tried with this 12M image: https://upload.wikimedia.org/wikipedia/commons/d/dd/Big_%26_Small_Pumkins.JPG
After digging into it a bit, I suspect it's because here the file is being served with
c.Stream
which doesn't seem to returnLast-Modified
header in the response.I tried changing it to
c.File
instead and I think it worked? I wasn't able to fully test the worst case scenario (mobile using data) because I wasn't able to build for linux-arm64 to deploy the changes to my server, but by building and deploying to my linux-x86-64 laptop and accessing it from the same machine I was able to seeLast-Modified
header in the responses and Firefox's Network Inspector did showTransferred: cached
.That being said, I'm not sending a PR for this since I'm not familiar with Go nor Echo, so maybe there was a reason for it being returned as a
c.Stream
initially?Vikunja Frontend Version
705afa0272
Vikunja API Version
6259dd8d42
Browser and version
No response
Can you reproduce the bug on the Vikunja demo site?
Yes
Screenshots
No response
Wow it would be amazing if this would fix the caching.
I also realised that for example the list background endpoint (e.g. https://try.vikunja.io/api/v1/lists/3/background) does have
content-type: image/jpg
but isn't a jpg but instead a blob that gets transformed viawindow.URL.createObjectURL(new Blob([response.data]))
. I always thought the caching problems were related to that the response is a blob and not an image and it would be best if the browser would actually cache both: the downloaded blob and the converted image.I do not remember why the service answers via blobs instead of the correct file in the first place. Would this change fix that?
I once tried to fix this on the frontend (if I remember correctly via caching in a service worker) but it seemed more effort than I had time at that moment.
Related, but not the same issue:
We really shouldn't push 12mb images to the client and have some kind of image proxy that helps us with the creation of images for
srcset
. Or do we have that already?The main reason to use
c.Stream
instead ofc.File
is the latter expects a file on disk. The way the storage is abstracted in Vikunja allows expanding this away from disk and to something like S3 in the future. In that case, we won't be able to usec.File
anyway.I think the proper solution would be to simply set the headers manually instead of relying on
c.File
doing that.You could try the network speed throttle (I think that's only available in Chromium though)
The fix would not change that. The background is only accessible with a JWT token and hence we need to put it in a blob after requesting it (with axios) and can't just let the browser do it with an
<img src="/api/v1/lists/3/background"/>
.We don't! That's another problem, related to the
content-type
header issue (the header is alwaysimage/jpg
, even if you upload a png).Any uploaded background should be converted to jpg with a quality of maybe 90 and resized to something like 4K if bigger before saving it to disk (that should solve this 12mb problem already). When requesting it, we should allow getting resized variants from a background image like we already can for avatars.
Cool, I tried this and seems to be working fine, I'll send a PR.
This can be closed, since it was fixed by vikunja/api#1376 right?