Skip to content

Commit ea34c1d

Browse files
darthmaimiansu
authored andcommitted
Add Service-Worker header to checkValidServiceWorker (#6753)
* Add header to checkValidServiceWorker (ts) * Add header to checkValidServiceWorker
1 parent 5ea3b34 commit ea34c1d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/react-scripts/template-typescript/src/serviceWorker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ function registerValidSW(swUrl: string, config?: Config) {
108108

109109
function checkValidServiceWorker(swUrl: string, config?: Config) {
110110
// Check if the service worker can be found. If it can't reload the page.
111-
fetch(swUrl)
111+
fetch(swUrl, {
112+
headers: { 'Service-Worker': 'script' }
113+
})
112114
.then(response => {
113115
// Ensure service worker exists, and that we really are getting a JS file.
114116
const contentType = response.headers.get('content-type');

packages/react-scripts/template/src/serviceWorker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ function registerValidSW(swUrl, config) {
100100

101101
function checkValidServiceWorker(swUrl, config) {
102102
// Check if the service worker can be found. If it can't reload the page.
103-
fetch(swUrl)
103+
fetch(swUrl, {
104+
headers: { 'Service-Worker': 'script' }
105+
})
104106
.then(response => {
105107
// Ensure service worker exists, and that we really are getting a JS file.
106108
const contentType = response.headers.get('content-type');

0 commit comments

Comments
 (0)