0.0.4 • Published 10 years ago
pageload-tools v0.0.4
Pageload tools
Tools to help you change site behavior based on pageload metrics. This is a collection of convenience methods for the Navigation Timing API
Usage
npm install pageload-toolsThis 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.
}
});API
connectTime()
Returns the number of milliseconds the browser took to establish a connection to the server.
loadTime()
Returns the number of milliseconds the page took to load, from navigationStart to loadEventEnd. Will return null if called before loadEventEnd has occurred.
dnsTime()
Returns the number of milliseconds the browser took to resolve DNS.