title: Forcing browser to clear all cache and
body: <p>I am working on a Progressive Web App. It's using WorkBox. When a user visits this site for the first time, it loads and saves everything in the cache. It loads <code>sw.js</code> on first hit, where all the caching programming is done. The problem is that when I change the <code>sw.js</code>, the browser doesn't load the new version. Browser isn't even fetching <code>sw.js</code> in all subsequent reloads. The browser is only hitting loading <code>sw.js</code> from the network only once and only the first time. Never after this. Whenever I close all tabs and re-open the site, everything is being loaded from the cache. There is no way for me to tell the browser to forget all cache and update the Service Working logic.</p>
  <p>When I investigated the headers, here are the response headers returned by the server when <code>sw.js</code> was loaded the first time.</p>
  <pre><code>GENERAL 
  
  Request URL: https://example.com/sw.js
  Request Method: GET
  Status Code: 200 
  Remote Address: 35.232.25.120:443
  Referrer Policy: strict-origin-when-cross-origin
  
  RESPONSE HEADERS
  
  accept-ranges: bytes
  content-disposition: inline; filename=&quot;sw.js&quot;
  content-encoding: gzip
  content-type: application/javascript; charset=utf-8
  date: Wed, 29 Dec 2021 10:43:11 GMT
  etag: &quot;c9fad0c2f5560c6ca6392666ce60c766ac2e745a&quot;
  server: nginx/1.19.0
  strict-transport-security: max-age=15724800; includeSubDomains
  vary: Accept-Encoding
  
  REQUEST HEADERS
  
  :authority: example.com
  :method: GET
  :path: /sw.js
  :scheme: https
  accept: */*
  accept-encoding: gzip, deflate, br
  accept-language: en-US,en;q=0.9
  cache-control: max-age=0
  cookie: _ga=GA1.3.1482851364.1640774590; _gid=GA1.3.498772445.1640774590; _gat_gtag_UA_175037391_1=1; amp_911ebe=adddib0vAFNA4kAE2aWvzU...1fo2sioje.1fo2siojf.0.1.1
  referer: https://example.com/
  sec-fetch-dest: serviceworker
  sec-fetch-mode: same-origin
  sec-fetch-site: same-origin
  service-worker: script
  user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
  </code></pre>
  <p>And following are the headers for <code>workbox-sw.js</code></p>
  <pre><code>GENERAL
  Request URL: https://storage.googleapis.com/workbox-cdn/releases/3.5.0/workbox-sw.js
  Request Method: GET
  Status Code: 200 
  Remote Address: 142.250.180.48:443
  Referrer Policy: strict-origin-when-cross-origin
  
  RESPONSE HEADERS
  
  accept-ranges: bytes
  access-control-allow-origin: *
  age: 799
  alt-svc: h3=&quot;:443&quot;; ma=2592000,h3-29=&quot;:443&quot;; ma=2592000,h3-Q050=&quot;:443&quot;; ma=2592000,h3-Q046=&quot;:443&quot;; ma=2592000,h3-Q043=&quot;:443&quot;; ma=2592000,quic=&quot;:443&quot;; ma=2592000; v=&quot;46,43&quot;
  cache-control: public, max-age=31536000
  content-encoding: gzip
  content-length: 810
  content-type: application/javascript; charset=utf-8
  date: Wed, 29 Dec 2021 10:29:53 GMT
  etag: &quot;e9e8605ff1fa99d1d728c7bef35972e3&quot;
  expires: Thu, 29 Dec 2022 10:29:53 GMT
  last-modified: Tue, 11 Sep 2018 14:57:59 GMT
  server: UploadServer
  vary: Accept-Encoding
  x-goog-generation: 1536677879504420
  x-goog-hash: crc32c=nfxN3w==
  x-goog-hash: md5=6ehgX/H6mdHXKMe+81ly4w==
  x-goog-metageneration: 1
  x-goog-storage-class: MULTI_REGIONAL
  x-goog-stored-content-encoding: gzip
  x-goog-stored-content-length: 810
  x-guploader-uploadid: ADPycdvVr9aa6mv9ryWENRCDQR0hmSBZZ3n3w0B5vnIKThJ-EFzRZaCLeyxxSaJhOZpMsSVEtWT1dtLnaxQwvUjKn2U
  
  REQUEST HEADERS
  
  :authority: storage.googleapis.com
  :method: GET
  :path: /workbox-cdn/releases/3.5.0/workbox-sw.js
  :scheme: https
  accept: */*
  accept-encoding: gzip, deflate, br
  accept-language: en-US,en;q=0.9
  cache-control: max-age=0
  referer: https://example.com/
  sec-fetch-dest: script
  sec-fetch-mode: no-cors
  sec-fetch-site: cross-site
  user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
  </code></pre>
  <p>It clearly shows that these files have to be cached by the browser for 30 days...</p>
  <p>Does it mean I have to wait for 30 days for <code>sw.js</code> to update itself?</p>
  <p>How can I solve it?</p>