Skip to content

Trigger asset caching from boot #1623

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

Closed
wants to merge 5 commits into from

Conversation

bgrgicak
Copy link
Collaborator

@bgrgicak bgrgicak commented Jul 18, 2024

Motivation for the change, related issues

We would like for Playground boot to control all aspects of the boot process including offline asset caching.

To do this we need a way to communicate between bootPlaygroundRemote and the service worker.

Implementation details

worker-thread.ts can now trigger cacheOfflineModeAssets which allows bootPlaygroundRemote to control offline asset caching.

cacheOfflineModeAssets now uses fetch instead of calling cache.addAll directly.
Because we call cacheOfflineModeAssets from the end of the boot process, caching is already working and all requests are cached.

If any of the files were already cached, they would be returned by cache instead of making a network request.

Testing Instructions (or ideally a Blueprint)

@bgrgicak bgrgicak self-assigned this Jul 18, 2024
@bgrgicak
Copy link
Collaborator Author

@adamziel @brandonpayton I'm exploring how to trigger cache.cacheOfflineModeAssets which is available in service-worker.ts from bootPlaygroundRemote.

What do you think about this approach? Do you have any other suggestions on how to do it?

Context:

  • bootPlaygroundRemote is in the main thread
  • worker-thread is a WebWorker
  • service-worker is a ServiceWorker

WebWorkers and ServiceWorkers can't communicate directly, so messages need to be relayed through the main thread.

Alternatively we could skip worker-thread and send a message directly from bootPlaygroundRemote to service-worker

@bgrgicak
Copy link
Collaborator Author

This doesn't work for me. The Web Worker isn't loaded on the first load so it doesn't relay the message to the service worker.

@bgrgicak
Copy link
Collaborator Author

I will focus on wrapping up offline support without triggering it from boot and we can explore this next week.

@bgrgicak
Copy link
Collaborator Author

Let's trigger fetch from boot to cache assets.

#1535 (comment)

@bgrgicak
Copy link
Collaborator Author

The current implementation in #1535 seems good as is. Let's close this PR without merging.

@bgrgicak bgrgicak closed this Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant