-
Notifications
You must be signed in to change notification settings - Fork 95
Description
Hi everybody,
I came across this script the other day while tuning my store maximum speed and Google Pagespeed love. Firstly it's great, easy to implement and works straight away. I personally was using the 'scroll' detection but for some pages there's little or no scrolling needed.
Looking around I found another handy speed hack here 'Delay Google Tag Manager' and borrowed the mousemove and touchstart to add to your script. Now whenever someone moves the mouse, touches the screen or scrolls the script triggers and everything pops into life :)
Weirdly on Chrome if you have the dev console open the mousemove fails to work unless you click a button (which then triggers the activity) but if you have a visual thing being hidden, for example I hide my review stars until you scroll,move,touch it's easy to see the script has triggered.
For those looking to experiment you'll need to make the following changes to the script at line 130
function scrollLoad(loadRule) {
var eventFn = partial(loadOnScroll, loadRule.originalUrl);
var eventOptions = supportsPassive ? {passive: true} : false;
window.addEventListener('scroll', eventFn, eventOptions);
window.addEventListener('mousemove', eventFn, eventOptions);
window.addEventListener('touchstart', eventFn, eventOptions);
function loadOnScroll(src) {
loadScript(src);
window.removeEventListener('scroll', eventFn, eventOptions);
window.removeEventListener('mousemove', eventFn, eventOptions);
window.removeEventListener('touchstart', eventFn, eventOptions);
}
}
Hope this helps somebody :)