I’d like to serve a service worker (sw.js). I can just put it in
/public but if I do that it doesn’t serve the right content type header.
How can I set the right content type header for assets in
/public? This knowledge would be useful for more than just this - but it would solve this problem too.
Even better - how can I use the build system, to serve a built bundle for the sw.js file? A pointer in the right location would be lovely. I guess I’d need to register a new type of end point (like server and client and maybe cordova). Is this even possible?
To get the right content header, I thought to use
WebApp.connectHandlers.use, but I’m not sure if that will block access to the file (I’ll try it - but I thought I’d ask anyway)
Another service worker question - I am planning to use it mostly for offline support in an app. I want to be able to do that per route - basically, each route represents a user definable experience, and that experience requires a bunch of files (images, etc.) It also requires a set of data from my mongo stores. I am using GroundDB in the application tier to take care of offline caching for that data, but I’m actually wondering - can I use a service worker for that? Can a service worker use Meteor’s DDP connection, grab data and stuff that into whatever GroudDB stuffs stuff into (I think LocalStorage)?
I suppose I should also ask if a service worker can (or should) be configured to collect data based on a route. If not, I’ll have to come up with some other way to cache my image assets for these end points…
Maybe I can create a cache in a service worker message?
It looks like this is the way to go - I’ll create a cache API in a Service Worker message response, and send my assets to that on the client side from my subscription to the Ground:DB. Pretty spiffy. Cache invalidation will be the next tricky step I suppose.
Okay, so after reading a little bit from Ben Newman, I’ll probably just end up using some pre-fetching and the standard browser cache to start, then maybe a localforage cache later (and a Cordova wrapper to increase my cache sizes).
What an interesting and complex area of tech.