A New Collection of Thoughtful Learning Apps — Now Available on iOS & Android

Image
I’m excited to share a set of mobile apps I’ve recently completed and published on both the Google Play Store and the Apple App Store. These apps are designed with a simple goal in mind: to make meaningful, structured content more accessible, whether you’re studying theology or improving your English vocabulary. 📱 Now Available on Both Platforms All apps are live and available for download: Google Play Developer Page: https://play.google.com/store/apps/dev?id=5835943159853189043 Apple App Store Developer Page: https://apps.apple.com/ca/developer/q-z-l-corp/id1888794100 📖 Theology & Confession Study Apps For those interested in Reformed theology and classical Christian teachings, I’ve developed a series of apps that present foundational texts in a clean, focused reading format: The Belgic Confession Canons of Dort Heidelberg Catechism Westminster Shorter Catechism Each app is designed to provide a distraction-free experience, making it easier to read, reflect, and revisit these im...

Make the Back Button Fast: A Practical Guide to bfcache

Make the Back Button Fast: A Practical Guide to bfcache


When a visitor presses Back or Forward, the browser has two common choices: rebuild the page from the network and JavaScript, or restore it almost instantly from memory. The second choice is the browser's back/forward cache, usually abbreviated as bfcache. It preserves the live page, pauses JavaScript execution, and resumes the page on return.

That sounds simple, but bfcache changes assumptions that many applications quietly rely on: pending timers can resume, a page may outlive navigation for longer than expected, and third-party embeds can affect whether the whole page qualifies. The goal is not merely to get the cache hit. It is to make restoration predictable.

Start by removing the unreliable unload hooks

Do not use unload. Browser behavior for this event is inconsistent, and Firefox, in particular, can make a page ineligible for bfcache when it finds an unload listener. Chrome and Safari have also deprecated or reduced their reliability around it. Use pagehide for cleanup that must run during navigation, but first classify the navigation:

window.addEventListener("pagehide", (event) => { if (event.persisted) { // The browser intends to keep this document in bfcache. closeNonessentialResources(); } else { // The document is likely to be destroyed. cleanupBeforeUnload(); } });

pagehide.persisted === true is an intention, not a guarantee: another browser rule or in-progress operation may still prevent caching.

beforeunload is different. It does not disqualify a page in the same straightforward way in modern browsers, but it should be used only to warn about unsaved changes. Register it conditionally, remove it as soon as the risk disappears, and remember that it cannot safely be treated as a cleanup hook.

function warnAboutUnsavedChanges(event) { event.preventDefault(); event.returnValue = ""; } window.addEventListener("beforeunload", warnAboutUnsavedChanges); // Remove it after the form is saved: window.removeEventListener("beforeunload", warnAboutUnsavedChanges);

Refresh state after restoration

The pageshow event fires for normal loads and bfcache restores. Its event.persisted property distinguishes the two. On a restore, use that moment to recheck server authorization, refresh data with stale-time rules, reconnect services, and resume work that should not remain paused.

window.addEventListener("pageshow", async (event) => { if (!event.persisted) return; await refreshPermissions(); await refreshVisibleData(); });

Do not assume every restored application action should silently rerun. A form may contain unsaved text; a search list may be valid from memory; an order screen may need fresh inventory. The cache restores a snapshot, so state reconciliation is an application decision rather than a generic reload.

Test actual navigations, not just a DevTools hint

  1. Open the target page in Chrome or another supported browser.
  2. Navigate to a second page on your site or an external page.
  3. Press Back and watch the pageshow event.
  4. If Chrome's bfcache tooling is available, inspect the Back/Forward Cache section for the exact blocking reason.
  5. Repeat with a third-party iframe and a completed versus in-progress IndexedDB operation.

Do not use Cache-Control: no-store as a blanket performance optimization. It is appropriate for sensitive pages that should not be cached, but it also reduces bfcache eligibility when browsers refuse to cache the page resource. For ordinary pages, prefer narrower cache controls and ensure dynamic content has an explicit freshness policy.

For ongoing diagnostics, Chromium exposes PerformanceNavigationTiming.notRestoredReasons. It can report reasons at the top level and for same-origin iframe children, but the API is experimental and browser support is not universal. Treat it as supplementary instrumentation, not as proof that a page is eligible everywhere.

const entries = performance.getEntriesByType("navigation"); const reasons = entries[0]?.notRestoredReasons; if (reasons) { console.log(reasons); }

A short bfcache checklist

  • Remove unload listeners and libraries that add them.
  • Add conditional beforeunload handling only for real unsaved work.
  • Use pagehide and pageshow.persisted for lifecycle transitions.
  • Close or reconnect resources where stale state could be harmful.
  • Check third-party frames, open database transactions, and privacy headers.
  • Verify restores with real Back/Forward navigation and browser-specific diagnostics.

bfcache is easy to describe and surprisingly easy to disrupt. The practical win comes from making navigation lifecycle behavior explicit, testing the restore path, and fixing the specific browser reason rather than treating every missing cache hit as a JavaScript defect.

References

❤️ Support This Blog


If this post helped you, you can support my writing with a small donation. Thank you for reading.


Comments

Popular Posts

react-native run-android : do not build/update modified code(App.js)

A New Collection of Thoughtful Learning Apps — Now Available on iOS & Android