Skip to content
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

Hosting multiple service workers on the same origin deletes the cache from other subdirectories #1344

Closed
BenLubar opened this issue Mar 4, 2018 · 5 comments
Labels
Bug An issue with our existing, production codebase. workbox-precaching
Milestone

Comments

@BenLubar
Copy link

BenLubar commented Mar 4, 2018

Library Affected:
workbox-precaching

Browser & Platform:
all browsers

Issue or Feature Request Description:
I have multiple web apps hosted on the same domain that each have a service worker set up to allow the use of the app offline. For example, https://benlubar.github.io/cmv2mp4/ and https://benlubar.github.io/df-ai/plan-editor/.

Setting a different cache name prefix on each only affects the name of the cache, which already contains the URL of the directory where the service worker is hosted. The IndexedDB is always named workbox-precaching and contains no information about which subdirectory the service worker is hosted in.

BenLubar added a commit to BenLubar/cmv2mp4 that referenced this issue Mar 4, 2018
@jeffposnick jeffposnick added Bug An issue with our existing, production codebase. workbox-precaching labels Mar 5, 2018
@jeffposnick jeffposnick added this to the V3 Stable milestone Mar 5, 2018
@jeffposnick
Copy link
Contributor

Thanks for reporting—that does seem like and oversight.

CC: @gauntface to confirm.

@gauntface
Copy link

Great point. Probably makes sense to name the database after the cache (assuming IDB doesn't get upset with the default cache name which includes the sw scope)

@gauntface
Copy link

So our mocks for IDB block the user of anything outside of this regex:

// Is the supplied identified a valid identifier?
const r_identifier = /^[a-z_][a-zA-Z0-9_\-\$]*$/;
function validIdentifier(identifier)
{
    if (typeof identifier === 'string' && identifier.match(r_identifier)) return true;
    else return false;
}

I'm not sure if this 100% valid since I tried the idb name:

workbox-precaching-`!@#$%^&*()http://helloworlx.com/

and everything was fine.

Couple of options are:

  1. find a way to get around the mock and hope this isn't an issue in browsers
  2. Use the cache name but remove any invalid characters

@jeffposnick
Copy link
Contributor

Going with scope.replace(/\W/g, '-') and using that as part of the IDB name seems like a reasonable enough capitulation to the demands of our IDB mock.

@gauntface
Copy link

@BenLubar I just published 3.0.0-beta.2 - if you get a chance, could you try it out with your setup and see if it works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug An issue with our existing, production codebase. workbox-precaching
Projects
None yet
Development

No branches or pull requests

3 participants