mozilla / oghliner

template and tool for deploying Offline Web Apps to GitHub Pages
https://mozilla.github.io/oghliner/
Apache License 2.0
115 stars 17 forks source link

consider supporting conditional/lazy caching of some assets #29

Open mykmelez opened 8 years ago

mykmelez commented 8 years ago

Sometimes images are conditionally downloaded, particularly responsive images that use <img srcset> to make the browser determine which one of a set to load, as described in Responsive Images: If you’re just changing resolutions, use srcset..

I'm not sure how often they're used in apps generally, much less offline-able apps hosted on GitHub Pages, but they're mentioned in Introduction to Service Worker at least, so at least some folks have spent some time thinking about how to handle them when using Service Worker to cache app assets.

Since the promise of Oghliner is to simply cache your whole app offline, I'm loathe to complicate the interface with conditional/lazy caching of assets. But perhaps it would make sense to include some support for caching one of several variants of an image.

For example, we might let users specify assets that shouldn't be cached immediately but should be cached once requested, something like:

{
    "filesToCacheLazily": [
        "images/logo-lo-res.png",
        "images/logo-hi-res.png",
    ],
}

Then the worker can cache whichever variant the browser ends up requesting.

Before we do something like this, however, we should have better use cases for it, ideally in the field.

marco-c commented 8 years ago

IIRC sw-precache allows you to define a set of dynamic URLs (that I guess are cached on request), or maybe it was broccoli-serviceworker.

marco-c commented 8 years ago

https://github.com/jkleinsc/broccoli-serviceworker/blob/345faa10a9a1b148171a5095eb725fe8ea10c4ff/lib/service-worker.js#L170

marco-c commented 8 years ago

This could be useful for localization files as well.