WEB-53Recommended
Keep the back button instant
Keep every page able to use the back/forward cache, which shows a page instantly on Back. Use no unload handlers, and no Cache-Control: no-store on ordinary pages.
How to do it
Use pagehide instead of unload. Send no-store only on pages with sensitive data, such as payment, health or identity pages, as private responses lists. Ordinary account pages use private, no-cache. Chrome now caches some no-store pages, but other browsers don't. Close open connections, such as WebSockets, on pagehide and reopen them on pageshow.
Examples
JavaScript example
let socket;
const connect = () => { socket = new WebSocket("wss://example.com/live"); };
connect();
addEventListener("pagehide", () => socket.close());
addEventListener("pageshow", (e) => {
if (e.persisted) connect(); // restored from the back/forward cache
});
How to check
DevTools › Application › Back/forward cache reports the page as restored. A browser test goes forward and Back, and the pageshow event has persisted set to true.
Sources
Related rules
- WEB-52 Fetch the next page on hover in Website
- APS-46 Keep private pages out of shared caches in Application security
- APP-22 Warn before leaving unsaved changes in Web app interface
- APP-78 Return people to where they were on Back in Web app interface
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/website/performance/bfcache">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.