Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

[Offline] Bug fix - cached files now serving in offline too #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

[Offline] Bug fix - cached files now serving in offline too #148

wants to merge 1 commit into from

Conversation

bekliev
Copy link

@bekliev bekliev commented Jun 3, 2019

I'm catched this issue on Windows 10.

Step-by-step what happens:

const files = [
    // ...
    "favicon.png",
    // etc. (cache-able files)
];

const to_cache = shell.concat(files).filter(n => n !== '.DS_Store');
const cached = new Set(to_cache);


// Our listener
self.addEventListener('fetch', event => {
    // ...

    /*
     * We cannot pass this condition, cause of: url.pathname is equal to "/favicon.png"
     * the source: `cached.has(url.pathname)` which will become `cached.has("/favicon.png")`
     * this fix will do the thing: `cached.has(url.pathname.slice(1)` which will become `cached.has("favicon.png")`
     */
    if (url.host === self.location.host && cached.has(url.pathname.slice(1))) {
        // serving...
    }

    // ...
});

@iztsv
Copy link

iztsv commented Jun 4, 2019

The same issue on macos. cached set contains urls which don't start with /, but url.pathname always starts with /.

@bekliev bekliev changed the title Bug fix - cached files now serving in offline too [Offline] Bug fix - cached files now serving in offline too Jun 8, 2019
@bekliev
Copy link
Author

bekliev commented Jun 8, 2019

I think this PR #138 would be better to approve and merge instead of mine.
Anyway check out both, please.

@benmccann
Copy link
Member

See sveltejs/sapper#1210. We should figure out where we want to fix it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants