Service Worker caches download links
See original GitHub issueIs this a bug report?
Yes
Can you also reproduce the problem with npm 4.x?
Yes
Which terms did you search for in User Guide?
Service Worker and Caching
Environment
N/A
Steps to Reproduce
The default ServiceWorker appears to cache files that it has not seen or downloaded. I have an api call which basically generates a zip to download, and is accessible via a http link. When a user navigates to this download URL by clicking on a link, the service worker intercepts the request, and tries to service the default index page.
With the ServiceWorker active, it appears that it is trying to retrieve this file from cache rather than requesting it from the server.
- (I think this is important) Have the homepage set to
"."in the package.json config. - Have a link somewhere on your application that points to a file via an API call
- Click on the think with the service worker active
Expected Behavior
The browser would download the file (as it does without the service worker active)
Actual Behavior
The service worker intercepts the download and serves the normal index.html file.
Suggested Behaviour
Have the whitelist exposed as a configuration so that a set of paths don’t invoke the service worker.
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (4 by maintainers)

Top Related StackOverflow Question
my advice here (not affiliated with create-react-app) is to build the service-worker.js yourself.
you don’t need to eject to take hold of this part of your project, you can leave the
registerServiceWorker.jsexactly as it is and do the following:create a sw-precache config file:
then install
sw-precache:and add something like this as part of your build script:
this is what i’ve been doing in a couple of production applications for a month or two now and it works very nicely.
never mind - just figured out.
You can overwrite
create-react-app’s default service worker by runningsw-precachedirectly inpackage.jsonafterreact-scripts buildlike so:"build": "react-scripts build && cd build && sw-precache --config ../sw-precache-config.js",Then you can add a
sw-precache-config.jsfile in the root folder where you can control the options for the serviceworker created bysw-precache