-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
runtimeCaching for Videos returned with 206 #793
Comments
Hey @piotr-cz thanks for replying. This article tells about a problem with versions of chrome lower than V87 (I got 131). They are recommending to use a workbox, what is actually right that what i am doing. So from my view the only opportunity i get from the article is to modify the vite-pwa defaults or write my own? Or did I misunderstand the article? |
After a few tests without a success I added back my old config. |
In my app I'm precaching videos at runtime like so: // vite.config.ts
export default defineConfig({
plugins: [
preact(),
VitePWA({
srcDir: 'src',
filename: 'sw.ts',
manifestFilename: 'app.webmanifest',
strategies: 'injectManifest',
injectRegister: false,
registerType: 'prompt',
manifest: false,
injectManifest: {
globPatterns: [
// Default
'**/*.{js,css,html}',
// Imported static assets
'assets/*.{jpg,png,svg,woff2}',
'assets/*.{mp3,mp4}',
// Our buddy favicon
'assets/icon/favicon.svg',
],
globIgnores: ['mockServiceWorker.js'],
// Tweak to cache videos
maximumFileSizeToCacheInBytes: 2.3 * 1024 * 1024,
},
}),
],
}) However I had to create my own So probably you just have to set up workbox to add |
Okay, thanks, so I guess I had to go the hard way and create an external file as long as there is no other way. Is it to share a short snippet of what you do in your sw.ts so i don't need to code it from scratch? |
First try setting |
Wont change anything, my new config: pwa: {
devOptions:{
enabled: true
},
strategies: 'generateSW',
injectRegister: false,
registerType: 'prompt',
manifest: false,
injectManifest: {
globPatterns: [
// Default
'**/*.{js,css,html}',
// Imported static assets
'assets/*.{jpg,png,svg,woff2}',
'assets/*.{mp3,mp4}'
],
// Tweak to cache videos
maximumFileSizeToCacheInBytes: 2.3 * 1024 * 1024,
},
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
runtimeCaching: [
{
urlPattern: /^https:\/\/videos\.pexels\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'pexels-video-cache',
expiration: {
maxEntries: 500,
maxAgeSeconds: 60 * 60 * 24 * 365 // <== 365 days
},
cacheableResponse: {
statuses: [0, 200, 206]
},
rangeRequests: true
}
},
{
urlPattern: /^https:\/\/images\.pexels\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'pexels-image-cache',
expiration: {
maxEntries: 20,
maxAgeSeconds: 60 * 60 * 24 * 365 // <== 365 days
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
]
}
} |
The In your config you then have to set However both strategies should work, the key is to add mp4 files in I remember having exactly similar problem when I was serving app locally with serve (there is not problem with Maybe your hosting is somehow configured to serve partial content instead of whole files? When serving app, with serve, response for videos includes Try this: curl -I https://<host>/assets/<video file>.mp4 |
If your case is like mine, then you are showing video using Browser fires a network request to stream video in chunks using header In the meantime service worker installs and downloads precached files. For this probably browser re-uses previously made requests (including that video) and throws an error because it can only add requests to Cache that have Workarounds could be to fetch full video file:
It's possible to use However users opening the app for the first time would have to wait for whole video to be downloaded to see it. Proper solution would be that in case service worker would detect Anyway the issue is not directly related to this package, but to Workbox or Service Workers in general so you'd get better hints in Workbox repo. If you find any working solution, please let me know. |
Thank you for your answers. I have already tried some of your first reply, but it didn't work for me. I will try again and stick to your second message. If I get any solutions that work, I'll let you know. |
Looks like the server needs to add |
Might be, but I'm able to reproduce the issue on localhost (no CORS involved) with npm run build && npx serve -p 4173 dist you need an app that uses |
Beware using opaque responses with caches: check the warning here https://developer.chrome.com/docs/workbox/caching-resources-during-runtime#opaque_responses_and_the_navigatorstorage_api |
This with this custom plugin: GoogleChrome/workbox#3288 (comment). I think that this issue may be closed and the discussion can continue on the workbox repo |
Hey, currently I am working on a simple Demo Page with some Images and Videos on it.
(I am using this small project as a POC)
I am working with Nuxt3 and configured the PWA in my Nuxt config (see below)
So I managed to cache the images with the Service Worker, but the Videos won't work correctly.
While trying to cache the Videos, the Browser returns:
Uncaught (in promise) TypeError: Failed to execute 'put' on 'Cache': Partial response (status code 206) is unsupported
So I added “rangeRequest: true”, but that still didn't fix it.
Is there a way to do this?
Thanks for your help
My Config:
I tried also
handler: NetworkFirst
and configuring a manifest won't even change anything.I am Using Chrome Version 131.0.6778.70 (Official Build) (arm64) on macOS Sequoia V15.1
While testing, I am using Incognito windows, so there are no extensions or other stuff blocking.
I also tried everything on localhost while running dev and deployed on CF pages as well.
The text was updated successfully, but these errors were encountered: