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

[Question] Service Worker configuration with Express #2412

Closed
chemitaxis opened this issue May 30, 2017 · 7 comments
Closed

[Question] Service Worker configuration with Express #2412

chemitaxis opened this issue May 30, 2017 · 7 comments

Comments

@chemitaxis
Copy link

Hi, I would like to know what is the best approach to disable the cache for some files in CRA.

I have configured my CRA with express like this:

// Always return the main index.html, so react-router
// render the route in the client
app.get('*', ensureAuthenticated, (req, res) => {
  res.sendFile(path.resolve(__dirname, 'index.html'));
});

My problem is that sw, is caching the response, and the ensureAuthenticated middleware is not triggering. How can I disable service-worker for this file?

Thanks!

@chemitaxis
Copy link
Author

chemitaxis commented May 30, 2017

To be more specific, I want to configure my service-worker.js to change these values:

var precacheConfig = [
  ['index.html', 'c6b583f23f6222402326f18538da5b0f'],
  ['static/js/0.a78b900b.chunk.js', '809363d4d0aba6576b8f37c9f2b66499'],
  ['static/js/1.25a58664.chunk.js', 'abd6c29dc97ae815422ffbbcaebe2da3'],
  ['static/js/2.8180718a.chunk.js', '278d57c68a52a249b673cc458c43408b'],
  ['static/js/main.9c6f578a.js', '8313bb4ffb557772171b671711c2bc02']
],

@gaearon
Copy link
Contributor

gaearon commented May 30, 2017

@jeffposnick

What kind of configuration change would this entail? If this is fixable by providing configuration, I think we might need to expose it as an optional key in package.json. Too many people need that.

@jeffposnick
Copy link
Contributor

I think the best option for users who don't want to/can't serve their index.html via the SW cache would be to opt-out of using service workers entirely, by removing the call to registerServiceWorker().

There's support for excluding certain files and/or modifying the navigation fallback HTML that's available if you're willing to eject, but for this use case, where you need to perform a server-side check before returning an HTML response, taking service workers (which are effectively a proxy that will bypass your server) out of the picture would make the most sense.

@gaearon
Copy link
Contributor

gaearon commented May 30, 2017

Okay, that’s reasonable. Thanks for replying!

@gaearon gaearon closed this as completed May 30, 2017
@chemitaxis
Copy link
Author

Ok, thanks. I will modify manually with a script after build ;)

@gaearon
Copy link
Contributor

gaearon commented May 30, 2017

You can just remove the service worker registration. I don't see why you'd need to modify the build output.

@chemitaxis
Copy link
Author

If I remove the sw registration, Do I need to create my own sw? Thanks!

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants