Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the Back Forward Cache #2306

Open
Tiggerito opened this issue Jan 12, 2023 · 1 comment
Open

Support the Back Forward Cache #2306

Tiggerito opened this issue Jan 12, 2023 · 1 comment

Comments

@Tiggerito
Copy link
Contributor

https://web.dev/bfcache/

The Back Forward Cache (bfcache) is a way to give users an instant page response when they browse back and forward. If I site does not support it, the page has to be reloaded from the server.

It is supported by Chrome, Firefox and Safari.

The Chrome browser now includes a way to test if a page supports the bfcache. I tested a few stores and they had some common issues:

image

The first was that there was code using the unload handler, which disables the bfcache. I tracked it down to what I think is some code in the jQuery bundled with the theme. The package code looks like this:

	// Accessing iframe documents after unload throws "permission denied" errors (jQuery #13936)
	// Support: IE 11+, Edge 17 - 18+
	// IE/Edge sometimes throw a "Permission denied" error when strict-comparing
	// two documents; shallow comparisons work.
	// eslint-disable-next-line eqeqeq
	if ( preferredDoc != document &&
		( subWindow = document.defaultView ) && subWindow.top !== subWindow ) {

		// Support: IE 11, Edge
		if ( subWindow.addEventListener ) {
			subWindow.addEventListener( "unload", unloadHandler, false );

		// Support: IE 9 - 10 only
		} else if ( subWindow.attachEvent ) {
			subWindow.attachEvent( "onunload", unloadHandler );
		}
	}

I'm not sure what can be done with this one?

The other issue is the presence of this header in the HTML response. no-store is another no-no for bfcache.

cache-control: no-store, no-cache, must-revalidate

CloudFlare controls those headers. It could be CloudFare adding it or passing it on from the original response. Maybe just the no-cache is enough. Is a no-store required?

@ImTheDeveloper
Copy link

Good spot this was on my to do list to sort out on our store. I've noticed Shopify themes seem to be quite snappy with the back button caching well but our BC stores suffering the full reload which is quite painful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants