Skip to content

If I shouldn't serve mockServiceWorker.js in production, then why "public" directory? #464

Answered by kettanaito
silvenon asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @silvenon.

We are going a bit too harsh on the warning so to make it clear you don't use MSW in production. In practice, you are right, just placing the worker script in a public directory will normally mean that it's also there in production. I trust it to your build setup to remove it when needed, e.g.

  - name: build
    run: npm run build && rm ./public/mockServiceWorker.js

Maybe we should be more explicit about this. The problem with mentioning this is that there are multiple ways to solve this and, ultimately, you should know best. So it's hard to recommend "one size fits all" approach.

Serving the worker script in production without registering it does nothing. It doesn't affec…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@kettanaito
Comment options

@silvenon
Comment options

silvenon Apr 16, 2025
Author Sponsor

@kettanaito
Comment options

Answer selected by silvenon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants