InstantClick 3.0 Released
instantclick.io
instantclick.io
Clicky dynamically adds a JS file to the header so it's asynchronous. It does the same every few minutes to poll and indicate someone's still on the page.
When used with InstantClick, the first tracking request worked fine. But when I clicked - the first AND second Clicky tracking request were sent. Another click meant 3 new requests were sent.
It puzzled me for a minute, before I realized. Clicky's JS didn't have InstantClicks' data-no-instant attribute, so all previous tracking scripts were being re-loaded with every click.
The fix is to push the tracking requests to Clicky manually via InstantClick's on change callback. Then I used JQuery to add the data-no-instant attr to all the clicky script tags in the head:
InstantClick.on('change', function() {
clicky.log(location.pathname+location.search, document.title, 'pageview');
// now stop any clicky scripts from being re-requested each time the page is insta-reloaded, to stop wasted tracking requests
jQuery("head script[src*='clicky.com']:not([data-no-instant])").attr('data-no-instant', true);
});
The same might happen with Google Analytics if you're using it asynchronously, but I've not tried that.Hope this helps someone if they see the same weirdness.
InstantClick
- InstantClick is a little easier to implement, with nothing required server-side
- InstantClick works to reduce latency by prefetching page content on hover.
- InstantClick always replaces the body's outerHTML
- InstantClick provides a YouTube style loading progress bar
Pjax[1] - You specify specifically which page element is replaced (using the ID)
- You set up your app to return only the required page fragment on ajax calls
- No loading bar is included, but can easily be added
- Content is not prefetched on hover
I think I still prefer the pjax approach because it sends less data over the wire. However, would be interesting to see a hybrid of the two approaches.Also worth noting that both essentially turn your site into a single-page app that updates the browser URL bar using pushState. Both approaches also degrade nicely.
InstantClick uses pushState and Ajax (a combo known as pjax), replacing only the body and the title in the head.If I spot anything weird I'll let you guys know.
Not sure how it works now but shouldn't Apple/Google just disable that delay if your viewport is already set to device-width? It's not like you're going to double-tap to zoom in any further.
Also, it generates a much larger server load. Look up FasterFox and the related controversy.
>FastClick: eliminating the 300ms delay between a physical tap and the firing of a click event on mobile browsers
>InstantClick: preloading links you are likely to click on
Deleted comment
Where this library shines is if you already have a decent, fast-ish website with ~500ms load times. This can bridge that final gap and make it look like the whole site is loading in a flash. Amazing to see in practice. It's more the fact that the page layout can be computed before the page changes. it makes a huge difference in perception.