pageshow
event to detect back navigation from cache and trigger location.reload()
to refresh content.window.scrollY
to sessionStorage
on unload and restoring it on load.You're looking to force content to refresh on browser back navigation in your Webflow site, while preserving the user's scroll position. This is a nuanced issue because default browser behavior typically restores the page from cache when the back button is used.
To refresh specific content without a full page reload (and scroll reset), you can use JavaScript to detect the pageshow event and conditionally reload data.
Add this small custom code to your Webflow project:
Go to Project Settings → Custom Code → Footer and insert:
```javascript
```
The event.persisted
detects when the page was loaded from the bfcache.
This forces the page to reload only if it was loaded via browser back/forward navigation.
Reloading the page resets the scroll position, but you can manually restore it using sessionStorage
.
Add this to the footer as well:
```javascript
```
This captures the scroll position before the user leaves the page and restores it on reload.
tag section, or do it globally via Project Settings → Custom Code → Footer.
To make your Webflow site refresh on back navigation while keeping scroll:
pageshow
event with location.reload()
to refresh if loaded from cache.sessionStorage
.This approach balances forced freshness with a seamless UX.