Fergal Daly | 7f642970 | 2024-12-11 05:30:31 | [diff] [blame] | 1 | # BFCache Overview |
| 2 | |
| 3 | ## TL;DR |
| 4 | |
| 5 | Without back/forward-cache (BFCache), |
| 6 | when the browser navigates away from a page, |
| 7 | it discards the DOM and all of the JS context. |
| 8 | If it returns to that page, |
| 9 | even if every resource is served from the HTTP cache, |
| 10 | it has to parse everything from scratch |
| 11 | and execute the JS in a fresh JS context. |
| 12 | With BFCache, |
| 13 | when the browser navigates away from a page, |
| 14 | it might just pause that page, |
| 15 | keeping everything fully intact. |
| 16 | If it returns to that page, |
| 17 | it can simply unpause it, |
| 18 | giving the user a much fast user-experience. |
| 19 | |
| 20 | ## Contact |
| 21 | |
| 22 | Please reach out to [bfcache-dev@chromium.org](mailto:bfcache-dev@chromium.org) for advice. |
| 23 | |
| 24 | ## Your feature and BFCache |
| 25 | |
| 26 | Ignoring BFCache can result in serious privacy problems. |
| 27 | The performance benefit provided by BFCache are enormous. |
| 28 | As a result, |
| 29 | it is not acceptable to launch a feature |
| 30 | and figure out BFCache later. |
| 31 | TAG, privacy and API owners |
| 32 | are all be on the look-out for APIs |
| 33 | that have not properly considered BFCache. |
| 34 | |
| 35 | There are many pre-existing features that are not compatible with BFCache. |
| 36 | Some are fundamentally incompatible given their current API/UX. |
| 37 | Some are potentially compatible |
| 38 | but predate BFCache in Chrome. |
| 39 | We have ensured that BFCache is disabled |
| 40 | when these features are active. |
| 41 | This avoids privacy problems |
| 42 | at the expense of performance. |
| 43 | We do not want to add to this list. |
| 44 | |
| 45 | ### Specs |
| 46 | |
| 47 | If your feature is part of the web platform, |
| 48 | you should ensure that BFCache |
| 49 | (and other non-fully-active states like prerendering) |
| 50 | are accounted for in the spec. |
| 51 | |
| 52 | The two main docs you need to read are |
| 53 | - https://www.w3.org/TR/design-principles/#support-non-fully-active |
| 54 | - https://w3ctag.github.io/bfcache-guide/ |
| 55 | |
| 56 | These are essential reading for all new WP features. |
| 57 | The privacy and security questionnaire for TAG review |
| 58 | contains a section on non-fully-active behaviour. |
| 59 | Chrome's privacy team also requires |
| 60 | specific consideration of BFCache |
| 61 | (and other non-fully-active documents) |
| 62 | during privacy reviews. |
| 63 | |
| 64 | ### Implementation |
| 65 | |
| 66 | Even if your feature is only a part of the browser, |
| 67 | you may still need to worry about BFCache. |
| 68 | If your feature interacts with pages |
| 69 | or reacts to page events or navigation |
| 70 | then it may need logic to cope with the fact that |
| 71 | pages are not necessarily destroyed |
| 72 | when navigation occurs |
| 73 | (an assumption that was correct for decades). |
| 74 | |
| 75 | [This doc](https://docs.google.com/document/d/1kR9QHWXXpoXsP3Y6JEDpIgZ5p7EgTTvdDN2kIrYdXcg/edit?tab=t.0#heading=h.b5k2sf3jhu99) |
| 76 | provides advice on how to make a feature behave nicely with BFCache. |
| 77 | Please also [contact us](mailto:bfcache-dev@chromium.org) |
| 78 | for explainer, design or code reviews. |