Skip to content
New issue

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

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

Already on GitHub? # to your account

Connecting to socket.io forces browsers to clear page cache #1660

Closed
yujiosaka opened this issue Jul 2, 2014 · 2 comments
Closed

Connecting to socket.io forces browsers to clear page cache #1660

yujiosaka opened this issue Jul 2, 2014 · 2 comments

Comments

@yujiosaka
Copy link

Page cache (bfcache) retains the entire page when go back and forward.
It is important especially for Mobile Safari and Android browser to give smooth UX.

However, connecting to socket.io automatically disables page cache.

I created a sample app and wrote details on it's readme.
https://github.com/yujiosaka/socket.io-cache-example

I wrote workaround to this problem, but is there a better way avoiding this problem?

@yujiosaka
Copy link
Author

Workaround:
It's not so good idea, but we circumvent this issue by disconnecting socket before leaving page.

iPhone does not support beforeunload event, so you need to bind click event to all links, which is why it's not so good idea.

We added the following lines with jQuery:

if (/iPhone|iPod|iPad|android/.test(navigator.userAgent)) {
  jQuery('a').click(function() {
    var href;
    href = $(this).attr('href');
    if (href && href.indexOf('#') !== 0 && href.indexOf('javascript:') !== 0) {
      socket.disconnect();
    }
  });
}

Let me know if there is a better solution/workaround for this issue.

@darrachequesne
Copy link
Member

That issue was closed automatically. Please check if your issue is fixed with the latest release, and reopen if needed (with a fiddle reproducing the issue if possible).

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

No branches or pull requests

2 participants