I have a userscript where I'd like to cache audio files from audio elements. fetch() isn't viable here as I have to wait for it to fetch to get a blob out of it. Is there a way to use the audio element itself for caching? The codec of the audio is FLAC.
1 Answer
If you use the appropriate Cache-Control header, the browser will cache for you. No other work is required.
For example:
Cache-Control: public, max-age=604800, immutable
5 Comments
Jaromanda X
that would require access to the server - at a guess, since OP is using
tampermonkey, they are trying to do this on a site that isn't theirs?Brad
@JaromandaX Tampermonkey can't alter response headers? I've never used it myself, but it seems like it should be able to, yeah?
Jaromanda X
You may be right, been years since I used it :p
SeetheMoar
I don't think Cache-Control can be used here as all the URL parameters change per visit except for one
Brad
@SeetheMoar Sad. In that case, yeah you need a Service Worker.
fetch() isn't viable here as I have to wait for ithow is that an issue?