Skip to content

Use of Cache-Control should be flagged by Site Health for unauthenticated frontend responses due to preventing bfcache #1692

Description

@westonruter

Browsers have typically prevented a page from being served from bfcache when is served with Cache-Control: no-store. For example, in Core-21938 this was done to prevent a cached page from being accessed after a user logs out of WordPress. However, there are many sites that serve Cache-Control: no-store even to unauthenticated requests. This is the number one reason for why bfcache is disabled in WP sites, as is seen at GoogleChromeLabs/wpp-research#75.

Chrome is currently experimenting with enabling bfcache when pages are served with Cache-Control: no-store, but there are scenarios still where such pages remain ineligible.

A Site Health test can be added which warns sites when they served unauthenticated responses with Cache-Control: no-store as this can make them ineligible for bfcache and thus negatively impact navigation performance.

Activity

  1. moved this to Not Started/Backlog 📆 in WP Performance Ongoingon Nov 21, 2024
  2. added
    Needs DevAnything that requires development (e.g. a pull request)
    Good First IssueIssue particularly suitable to be worked on by new contributors
    on Nov 26, 2024
  3. moved this from Not Started/Backlog 📆 to To Do 🔧 in WP Performance Ongoingon Nov 26, 2024
  4. westonruter commented on Nov 29, 2024

    @westonruter
    MemberAuthor

    This may end up being important for Speculative Loading as well (h/t @yoavweiss):

    Looks like Chromium is about to change how prefetches behave, so that only cacheable resources will be served from the prefetch cache: https://groups.google.com/a/chromium.org/g/blink-dev/c/Zdo71C0k9C0/m/BRXW6aQiAAAJ

    If you're prefetching your HTMLs, make sure they are actually cacheable, even with a short lifetime.

  5. gilbertococchi commented on Nov 29, 2024

    @gilbertococchi

    That's an interesting insight, +1.

    Also, if a WP Site uses Speculation Rules Prefetch or Prerender having BFCache working is particularly important in case of following back/forward navigations.

    Speculation Rules is an API that works really well in combination with BFCache (not being blocked) and/or Cross Document View Transition.

  6. westonruter commented on Nov 29, 2024

    @westonruter
    MemberAuthor

    This may make sense to propose as part of the core merge for Speculative Loading since it if the Cache-Control header prevents Speculation Rules from working, then having the feature enabled in core would only wastefully increase server load without improving the user's navigation experience.

    See Core-62503 and WordPress/wordpress-develop#7860.

    cc @felixarntz

  7. changed the title [-]Use of `Cache-Control: no-store` should be flagged by Site Health for unauthenticated frontend responses[/-] [+]Use of `Cache-Control`: `no-store`, `no-cache`, `max-age=0` should be flagged by Site Health for unauthenticated frontend responses[/+] on Nov 29, 2024
  8. westonruter commented on Nov 29, 2024

    @westonruter
    MemberAuthor

    Speculative Loading should also then be disabled automatically when a user is logged-in.

  9. westonruter commented on Nov 29, 2024

    @westonruter
    MemberAuthor

    Speculative Loading should also then be disabled automatically when a user is logged-in.

    I've filed this as #1709.

  10. removed
    Good First IssueIssue particularly suitable to be worked on by new contributors
    on Nov 29, 2024
  11. moved this from To Do 🔧 to Definition ✏️ in WP Performance Ongoingon Nov 29, 2024
  12. removed
    Needs DevAnything that requires development (e.g. a pull request)
    on Nov 29, 2024
  13. westonruter commented on Jan 16, 2025

    @westonruter
    MemberAuthor

    @b1ink0 Given your recent experience on Site Health tests #1727 and #1762 you may want to pick this up as well.

  14. b1ink0 commented on Jan 16, 2025

    @b1ink0
    Contributor

    @westonruter
    I have a few questions regarding the implementation to clarify things:

    1. From what I understand, we need to add this check for the HTML page, such as the home page, and verify its header—but not for the assets, correct?
    2. If we need to add this check for the assets as well, then integrating the assets check into #1727 seems like a better approach, while handling the HTML page check as a separate site health check.
  15. gilbertococchi commented on Jan 16, 2025

    @gilbertococchi

    @westonruter I took a stab at looking at the HTTP Archive data and it looks like there are at least 547k WP Origins using CCNS to date.

  16. westonruter commented on Jan 16, 2025

    @westonruter
    MemberAuthor
    1. From what I understand, we need to add this check for the HTML page, such as the home page, and verify its header—but not for the assets, correct?

    Correct! Doing one HTTP GET request to the homepage.

    1. If we need to add this check for the assets as well, then integrating the assets check into #1727 seems like a better approach, while handling the HTML page check as a separate site health check.

    No, this doesn't relate to the assets. So I think these two tests are related but distinct.

  17. moved this from Definition ✏️ to To Do 🔧 in WP Performance Ongoingon Jan 16, 2025
  18. changed the title [-]Use of `Cache-Control`: `no-store`, `no-cache`, `max-age=0` should be flagged by Site Health for unauthenticated frontend responses[/-] [+]Use of `Cache-Control` should be flagged by Site Health for unauthenticated frontend responses due to preventing bfcache[/+] on Jan 20, 2025
  19. moved this from To Do 🔧 to Done 😃 in WP Performance Ongoingon Jan 24, 2025
  20. westonruter commented on Jan 25, 2025

    @westonruter
    MemberAuthor

    Follow-up: #1825

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions