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

Suggestion: Only preload pages once per page load #132

Closed
robgraeber opened this issue Mar 16, 2016 · 9 comments
Closed

Suggestion: Only preload pages once per page load #132

robgraeber opened this issue Mar 16, 2016 · 9 comments

Comments

@robgraeber
Copy link

Hey it seems like repeatedly mousing over over links is loading the next page multiple times. I think limiting preloading to once per page load or something like once every 30 sec would really help cut down on page loads on the backend.

@bevdam
Copy link

bevdam commented Mar 17, 2016

I think it's also important to remember that once a page is preloaded it should be cached. Therefore, it should not have to hit the server again. I also think if I am not mistaken that if the mouse leaves the link the loading is stopped.

@robgraeber
Copy link
Author

The pages aren't necessarily cached, when I mouseover links on instantclick.io I see a bunch of 200 requests in the network tab. Best case is 304 responses if your server supports it.

@bevdam
Copy link

bevdam commented Mar 18, 2016

Yeah HTML is never really cached but If you can I recommend doing it when using this plugin cache the pages for and hour or so. Would depend on the page content as well. If you are looking to reduce server load or update the plugin as you suggested.

@robgraeber
Copy link
Author

It was more difficult than I expected, but I got some basic preload caching working on a fork. Seems like everything is setup to handle 1 preload at a time, so I changed it to only cache the last moused over link.

Here's the diff for reference: effinggames/instantclick@b0c0443

Ideally it would cache multiple requests at a time, but that would take a big refactor. Or a clever way to cache XMLHttpRequest's.

@robgraeber
Copy link
Author

Okay got the caching working with multiple requests. Didn't have to refactor too much, was able to store cached xhr objects and feed them in.

My fork: https://github.com/robgraeber/instantclick2

And diff: effinggames/instantclick@bc6f9f2...master

@bevdam
Copy link

bevdam commented Mar 24, 2016

This is cool

@ahmedhagii
Copy link

the first issue I noticed when I heard about instantclick, came to open an issue and found this :) great fix 👍

@onigetoc
Copy link

onigetoc commented Jul 1, 2016

On mouve hover, store the url, if another mouse hover is done, then check the last mouse hover url and do not preload it. I did this for my Wordpress plugin Zajax.
https://wordpress.org/plugins/zajax-ajax-navigation/

@dieulot
Copy link
Owner

dieulot commented Oct 25, 2016

You can use caching with InstantClick the same way you do without InstantClick: by setting Expires headers on the server. Implementing caching in JavaScript would be uselessly redundant. Setting caches on the server instead of in JavaScript has other benefits:

  • It will work when the page is opened in another tab.
  • It’s not dependant on InstantClick, so it will still work if you stop using InstantClick on your site.
  • It works for browsers that don't support InstantClick.

The big benefit to implement caching in JavaScript would be that it would cache out of the box, but not every site needs caching. When you have highly-dynamic content, such as a forum where new messages get posted nearly every second, you don’t want to have lagging content.

@dieulot dieulot closed this as completed Oct 25, 2016
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

5 participants