Skip to content

Service Worker returning old files #7829

@johannes-z

Description

@johannes-z

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

not applicable

Developer environment

Windows

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

  • browser version
  • SPFx version
  • Node.js version
  • etc

Describe the bug / error

The ServiceWorker returns old files for files served from SharePoint, e.g. Style Library, even when using url args for cache busting.
When loading a script with <script src=".../Style Library/script.js"></script>, the ServiceWorker returns random versions (latest or an older version) of that file.

On a simple page I'm loading the same file, config.js, twice. I've added the current Date in ms as url args to get the latest version, but it doesn't work.

Request URL: `.../Style%20Library/config.js?1648200666963`

date: Fri, 25 Mar 2022 09:31:05 GMT
etag: "{8209E62C-313F-4763-B3F5-6B6D0EEEB56E},11pub"
last-modified: Fri, 25 Mar 2022 09:30:41 GMT
Request URL: `.../Style%20Library/config.js?1648200666965`

date: Fri, 25 Mar 2022 09:31:05 GMT
etag: "{8209E62C-313F-4763-B3F5-6B6D0EEEB56E},10pub"
last-modified: Tue, 16 Nov 2021 09:21:43 GMT

When I Clear site data, the ServiceWorker seems to return the correct version. I've seen behavior though, where the ServiceWorker would sometimes still serve old files.
image

The only reliable way of getting the latest files is to disable the service worker under Application > Service Workers > Bypass for network and activating Network > Disable Cache.

I've had many co-workers and customers complain about seeing old file versions.

Steps to reproduce

  1. Upload a file to a Style Library
  2. Load the file (via requirejs, script-tag, fetch, etc.)
  3. Update the file
  4. Load the file again.
    1. The ServiceWorker should return either the latest or an older version.
    2. Rinse & repeat - the behavior seems non-deterministic

Expected behavior

The ServiceWorker caches files to long, or doesn't realise it should serve a newer file. Also cache busting to prevent caching doesn't work at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋Original poster responded to request for feedback, awaiting attention from Microsoft / community.area:swService Worker related issuestype:archive-old-issueIssues which are closed as tool old for active worktype:bug-suspectedSuspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions