Spomky-Labs / pwa-bundle

PHP library for generating a full featured PWA manifest
https://pwa.spomky-labs.com
MIT License
28 stars 1 forks source link

match_callback: 'origin: cdn.jsdelivr.net' not working as expected. #191

Closed tacman closed 1 week ago

tacman commented 2 weeks ago

Version(s) affected

1.2.x

Description

I'm moving this from #148 because I think it's a bug or perhaps the documentation can be improved.

                - match_callback: 'origin: cdn.jsdelivr.net'
                  strategy: 'CacheFirst' # or CacheOnly
                  preload_urls: 
                      - 'https://cdn.jsdelivr.net/npm/onsenui@2.12.8/js/onsenui.min.js'
                      - 'https://cdn.jsdelivr.net/npm/onsenui@2.12.8/css/ionicons/css/ionicons.min.css'
                      - 'https://cdn.jsdelivr.net/npm/onsenui@2.12.8/css/onsen-css-components.min.css'

This library never changes, so I really just want to cache it once when the application starts up.

It does not appear that this is working, though, as the other assets show that they are delivered via the service worker, but not the jsdelivr ones.

image

How to reproduce

Go to

https://pwa-last-stack.survos.com/en/mobile/start

and look at the console network

Possible Solution

No response

Additional Context

No response

Spomky commented 2 weeks ago

Hello @tacman,

Can you try with match_callback: 'origin: https://cdn.jsdelivr.net'? It looks like the function is using the scheme as well.

tacman commented 2 weeks ago

On a related note, I'd like to make sure my s3 urls are cached and/or preloaded. We launched an audio-tour last night, but the exhibition was an old stone building with lousy internet, a perfect application for pre-fetching. There was good internet at the entrance, in the ideal world they'd have gotten all the images and audio at the entrance when they first installed it.

tacman commented 2 weeks ago

Can you try with match_callback: 'origin: https://cdn.jsdelivr.net'?

No, that created lots of errors. Lemme add this to a demo repo that has s3 and jsdelivr urls that need to be cached. Thanks!

tacman commented 2 weeks ago

What is the difference between workbox-strategy and StrategyHandler?

image

In this case, I've setup

    serviceworker:
        enabled: true
        src: "sw.js"
        skip_waiting: true
        workbox:
            resource_caches:
                - match_callback: 'origin: cdn.jsdelivr.net'
                  strategy: 'CacheOnly'
                  preload_urls: # Optional, but you are now sure the library is preloaded even if used on another page the user never met before
                      - 'https://cdn.jsdelivr.net/npm/onsenui@2.12.8/js/onsenui.min.js'
                      - 'https://cdn.jsdelivr.net/npm/onsenui@2.12.8/css/ionicons/css/ionicons.min.css'
                      - 'https://cdn.jsdelivr.net/npm/onsenui@2.12.8/css/onsen-css-components.min.css'
                      - 'https://cdn.jsdelivr.net/npm/onsenui@2.12.8/css/material-design-iconic-font/fonts/Material-Design-Iconic-Font.woff2?v=2.2.0'
                      - 'https://cdn.jsdelivr.net/npm/onsenui@2.12.8/css/material-design-iconic-font/css/material-design-iconic-font.min.css'
                      - 'https://cdn.jsdelivr.net/npm/onsenui@2.12.8/css/font_awesome/webfonts/fa-brands-400.woff2'
tacman commented 2 weeks ago

Ah, I see, it has to do with the first time it's loaded. OK, not sure why this seems to be working in my test project, I'll keep digging.

Spomky commented 2 weeks ago

What is the difference between workbox-strategy and StrategyHandler?

🤔That's a very good question. but honestly I don't know.

Ah, I see, it has to do with the first time it's loaded. OK, not sure why this seems to be working in my test project, I'll keep digging.

I will give it a try on my side too by tuning the match callback w/o scheme, port or whatsoever.

tacman commented 2 weeks ago

What do you think about adding match debugging, like the Symfony route debugging.

image

Spomky commented 1 week ago

THis is something I wanted to do, but it can only partially be achieved. It requires information de profiler cannot have. The callback receives several arguments that are namely:

We only have the Url can easily be converted into an object. Other values are hard or impossible to guess.

tacman commented 1 week ago

Is it possible that the skip_waiting option is responsible for this behavior?

My pwa.yaml file was created when 1.0 first was in beta, and it's been copied to every project since. But I noticed that you enable it by default now. #59

tacman commented 1 week ago

I'm going to close this, because I'm unable to reproduce it now.