Skip to content

Offline fallback broken, gates on navigator.onLine which lies #64

Closed

Description

@drios05

fetch handler in sw.js only checks cache when navigator.onLine is false. That flag doesn't reliably flip on real disconnects, so the check fails, cache never gets hit, browser shows its native offline page instead of the app.

self.addEventListener('fetch', function (event) {
    let online = navigator.onLine
    if (!online) {
        event.respondWith(caches.match(event.request)...)
    }
});

Repro: load once online, kill network, reload.

Fix: try network, catch failure, fall back to cache. Don't bother checking online status at all.

self.addEventListener('fetch', function (event) {
    event.respondWith(
        fetch(event.request).catch(function () {
            return caches.match(event.request).then(res => res || caches.match('index.html'));
        })
    );
});

Activity

  1. amitmerchant1990 commented on Aug 6, 2026

    @amitmerchant1990
    Owner

    Thank you, @drios05

    Just updated the strategy based on this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions