BFCache Tip

Ever navigate back on a mobile site and find the menu still open? 🤔 That’s the Back/Forward Cache (BFCache) at work.

While great for performance, it can create a clunky user experience by preserving UI states you’d rather reset.

Inspired by a recent post from Erwin Hofman, I put together a couple of lightweight snippets to solve this.

They detect when a page is restored from BFCache and cleanly close the mobile menu.

Here are the solutions:

It’s a small improvement for a smoother UX. Hope this helps someone!

Discuss on Linkedin