MicrosoftEdge / MicrosoftEdge/WebView2Feedback

[Problem/Bug]: Webview2 cache not consistent, does not respect max-age or ETag

Open
#4,687 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

What happened?

I have a WebView 2 application with a request handler that can generate preview images, which are then served to the frontend as PNG files.
These files should be cached so that they are not regenerated if the URL is the same.

When handling the request in WebView2, I include a Cache-control header of the form
Cache-Control: private, must-revalidate, max-age=3600

I expect this to cache the image for an hour.

What I find though, is that the image is not cached for the entire period, WebView2 will make another request to this URL before an hour has passed.
It does not seem to follow a particular rule, the request does get cached, but it seems to rerun the request anyway.
This seems to happen after a few separate requests have been handled, the previous requests are removed from the cache.

I have also added an ETag header to the request, to verify if it is for an existing image. Even though I send this header in the request, the response never includes an equivalent 'If-None-Match' header.

I would expect WebView2 to only rerun the request when max-age has passed, and to include the 'If-None-Match' header to verify if the content is the same when the original request includes the ETag header.

Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

126.0.2592.102

SDK Version

1.0.2151.40

Framework

Win32

Operating System

Windows 11

OS Version

No response

Repro steps
  1. Setup an add_WebResourceRequested handler inside WebView2 to catch a request.
  2. Request a resource from the frontend which matches the filter.
  3. In the handler, set a Cache-Control Header to 'private, must-revalidate, max-age=3600' and an ETag header to '123'.
  4. Repeat the request from the frontend multiple times for separate images.

Expected:
The first request goes to the handler, subsequent requests use the cache. The ETag is sent on any stale data as the 'If-None-Match' header.
Actual:
Some of the requests use the cache, but not all of them.

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the add_WebResourceRequested handler described in the reproduction steps and reproduce the behavior using multiple frontend image requests. Inspect the Cache-Control, ETag, and subsequent request headers across repeated requests, including the WebView2 runtime version listed here. Done means the cache behavior and If-None-Match handling are either corrected or clearly characterized against the stated expectations.

Written by the indexing model from the issue text.

Assessment

Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.