Tools to help you change site behavior based on pageload metrics. This is a collection of convenience methods for the Navigation Timing API
npm install pageload-tools
This module is distributed in UMD format so you can use WebPack, Browserify, or drop the script right on the page In your code:
<script src="pageload-tools.js"></script>
or:
import pageloadTools from 'pageloadTools'
or:
var pageloadTools = require('pageload-tools');
Then you can change behavior of your site:
document.addEventListener("DOMContentLoaded", function(event) {
console.log('Total pageload time:', pageloadTools.loadTime());
if (pageloadTools.loadTime() > 5000) {
alert('Pageload was really slow, sorry!')
// disable heavy ajax features, preload data, etc.
}
});
Returns the number of milliseconds the browser took to establish a connection to the server.
Returns the number of milliseconds the page took to load, from navigationStart
to loadEventEnd
. Will return null if called before loadEventEnd
has occurred.
Returns the number of milliseconds the browser took to resolve DNS.