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

Document how to cache an external library #148

Open
tacman opened this issue Mar 20, 2024 · 2 comments
Open

Document how to cache an external library #148

tacman opened this issue Mar 20, 2024 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@tacman
Copy link
Contributor

tacman commented Mar 20, 2024

Description

I found a good javascript library for making mobile apps, onsenui, but I can't get it to work with AssetMapper

symfony/symfony#54342

Instead, I'm adding the script tag at the top, which works, but of course requires an internet connection. How would I add this as a pre-cached URL and CacheOnly, so it would work with offline?

<script src="https://cdn.jsdelivr.net/npm/onsenui@2.12.8/js/onsenui.min.js"></script>

In particular

Please note that you can refer to any URLs, but only URLs served by your application will be cached.

on https://pwa.spomky-labs.com/the-service-worker/workbox/warm-caching

@Spomky
Copy link
Member

Spomky commented Mar 20, 2024

Something like as follows should work (not tested)

pwa:
    serviceworker:
        enabled: true
        src: "sw.js"
        workbox:
            resource_caches:
                - match_callback: 'origin: cdn.jsdelivr.net'
                  strategy: 'CacheFirst'
                  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'

@Spomky Spomky self-assigned this Mar 21, 2024
@Spomky Spomky added the question Further information is requested label Mar 21, 2024
@tacman
Copy link
Contributor Author

tacman commented May 2, 2024

I'm revisiting this, because last night the jsdelivr cdn was down for several hours because the certificate had expired. LOTS of sites broke, and I was reminded that at least for existing users (not new visitors) if I had this implemented it would have continued to work for a bit.

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

                - match_callback: 'origin: cdn.jsdelivr.net'
                  strategy: 'CacheFirst'
                  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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants