Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to cache WAV or FLAC audio in Service Worker #66

Open
meduzen opened this issue Feb 8, 2023 · 0 comments
Open

Allow to cache WAV or FLAC audio in Service Worker #66

meduzen opened this issue Feb 8, 2023 · 0 comments
Assignees
Labels
pipes 🚰 Front-end dependencies and tooling

Comments

@meduzen
Copy link
Contributor

meduzen commented Feb 8, 2023

Depending on the audio capabilities of the device, people might be served FLAC (prefered) or WAV (fallback) sounds.

const format = document.createElement('audio').canPlayType('audio/flac').length > 0 ? 'flac' : 'wav'

However, in the Service Worker cache, the app only caches FLAC.

'sfx/smb-bump.flac',
'sfx/smb-coin.flac',
'sfx/smb-1up.flac',
'sfx/smw-bump.flac',
'sfx/smw-coin.flac',
'sfx/smw-1up.flac',

It could be great to cache the supported type.

Proposed approaches:

  • There’s no DOM access from a Service Worker, but the HTTP Accept header might be useful, thou it has to be checked if it can be used when building the request (and not when intercepting it) during the caching process.
  • Let the app communicate to the Service Worker what’s the supported format, and even let the app send the list of audio files to cache to the Service Worker at request time. As additional benefit, there should be no need to update the Service Worker in order to request an update of audio files and the update flow would be:
    1. Service Worker says “I’m ready” to the app.
    2. The app says “thanks, here are the audio files I need” (with the right format) to the Service Worker.
    3. The Service Worker checks which files are not cached yet, and cache them.
@meduzen meduzen added the pipes 🚰 Front-end dependencies and tooling label Feb 8, 2023
@meduzen meduzen self-assigned this Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pipes 🚰 Front-end dependencies and tooling
Projects
None yet
Development

No branches or pull requests

1 participant