Your Back button is losing you sales: fixing bfcache on e-commerce sites
A shopper opens a product, taps Back , and the catalog loads from scratch: filters reset, scroll position lost, infinite scroll back to page one. On mobile, where people jump between the list and product pages a dozen times per visit, this is one of the quietest conversion killers we see in e-commerce audits. Browsers already have a fix for it. It's called the back/forward cache (bfcache) : when…
When users navigate back on an e-commerce website, the browser can save time by restoring the previous page from memory using a feature called the back/forward cache (bfcache). This includes retaining scroll position, filters, and other page state. However, many stores unintentionally opt out of this feature, leading to a poor user experience and lost sales. To identify and fix bfcache issues, follow these steps:
1. Use Chrome DevTools to test if your pages are eligible for bfcache. Run the test on catalog pages, product pages, and search results, as these are where users most frequently use the back button. Check the navigation entries for any reasons the page wasn't restored, which could reveal blocking scripts.
2. Analyze real user data to pinpoint the scripts causing bfcache misses. Use performance.getEntriesByType('navigation') to check the notRestoredReasons property. Common blockers include unload listeners from analytics snippets, chat widgets, and A/B testing tools. Replace these with pagehide or visibilitychange events, which work in more browsers and cover tab switching and mobile app close scenarios.
3. Ensure your pages are not excluded from bfcache due to Cache-Control: no-store headers. While this is useful for pages like carts and checkouts, applying it site-wide can prevent users from efficiently navigating the catalog. Check the Cache-Control headers of your category pages and limit no-store to pages with personal data only.
4. Close open connections like WebSockets and WebRTC when the page is hidden, and reopen them when the page returns. This allows the browser to cache the page correctly. Also, handle the restore properly by refreshing data that may have changed, such as the cart badge and stock badges, using the pageshow event with event.persisted === true.
5. If your site uses infinite scroll, maintain the current state in the URL when the page is cached. This ensures users return to the same listing instead of the beginning of the page when bfcache misses. Use the URLSearchParams API to store the current page and filters in the URL's search parameters.
By implementing these steps, you can optimize your e-commerce site's bfcache usage, improving navigation speed and user experience, leading to higher conversion rates.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.