Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for bfcache compatibility incorrectly flags use of no-cache and max-age=0 #1825

Closed
westonruter opened this issue Jan 25, 2025 · 1 comment · Fixed by #1826
Closed

Test for bfcache compatibility incorrectly flags use of no-cache and max-age=0 #1825

westonruter opened this issue Jan 25, 2025 · 1 comment · Fixed by #1826
Labels
[Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only [Type] Bug An existing feature is broken

Comments

@westonruter
Copy link
Member

westonruter commented Jan 25, 2025

The bfcache Site Health test (#1692 fixed via #1807) is currently checking for no-cache and max-age=0 when in reality it shouldn't be.

From Back/forward cache on Web.dev:

For pages that need to always serve up-to-date content—and that content does not contain sensitive information—use Cache-Control: no-cache or Cache-Control: max-age=0. These directives instruct the browser to revalidate the content before serving it, and they don't affect a page's bfcache eligibility.

Note that when a page is restored from bfcache, it is restored from memory, not from the HTTP cache. As a result, directives like Cache-Control: no-cache or Cache-Control: max-age=0 are not taken into account, and no revalidation occurs before the content is displayed to the user.

This article from Nitropack:

3. Use Cache-Control: no-store only with information-sensitive pages

If a page contains sensitive information and caching is inappropriate, then Cache-Control: no-store should be used to prevent it from being eligible for bfcache. On the other hand, if a page doesn't contain sensitive information and always requires up-to-date content, Cache-Control: no-cache or Cache-Control: max-age=0 can be used. These directives prompt the browser to revalidate the content before serving it and don't impact a page's eligibility for bfcache.

And in Monitoring bfcache blocking reasons on MDN, the only blocking reason for Cache-Control is the no-store directive:

"response-cache-control-no-store"

The page uses no-store as a Cache-Control header value.

And the Lighthouse audit strings:

https://github.com/GoogleChrome/lighthouse/blob/af88b935e3669601cef2d6adf7186a6624731446/core/lib/bf-cache-strings.js#L172-L175
https://github.com/GoogleChrome/lighthouse/blob/af88b935e3669601cef2d6adf7186a6624731446/core/lib/bf-cache-strings.js#L196-L200

Also, I tested serving pages with Cache-Control: no-cache, max-age=0 and the DevTools check showed it was successfully served from bfcache:

Image

However, if I instead serve Cache-Control: no-store then I get a failure:

Image

So the no-cache and max-age=0 checks should be removed from the test.

@westonruter
Copy link
Member Author

Fixed by #1826

@github-project-automation github-project-automation bot moved this from Code Review 👀 to Done 😃 in WP Performance 2024 Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only [Type] Bug An existing feature is broken
Projects
Status: Done 😃
Development

Successfully merging a pull request may close this issue.

1 participant