<!—Firefox Prefetching -->
<link rel="prefetch" href="http://www.example.com/page2.html">
<!—Chrome Prefetching -->
<link rel="prerender" href="http://www.example.com/page2.html">
If I had Javascript on the page to prerender/prefetch (such as Google Analytics JS), will the prerender/prefetch execute Javascript on the page? Or does it delay any execution of JS until the page is actually requested by the user?
I've just done some more research on this:
Prefetch
will load the top level resource which is often simply the HTML page
Prerender
will fetch child elements as well, and will execute Javascript code. Using the Page Visibility API we can determine the current visibility state of the loaded page.
So the answer is yes, it will execute JS as long as the user is on Chrome and prerender is being used. Also, the current version of Google Analytics makes full use of the Page Visibility API so statistics wont be skewed, however it's likely there is a lot of code in the wild whose statistics are being skewed by not properly handling cases of prerendering.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With