GithubHelp home page GithubHelp logo

tools-alexuser01 / loading-stats Goto Github PK

View Code? Open in Web Editor NEW

This project forked from henrikjoreteg/loading-stats

0.0 3.0 0.0 112 KB

Client module for reporting real-world single page application performance back to you in your metrics.

JavaScript 100.00%

loading-stats's Introduction

loading-stats

Getting real-world performance metrics from deployed single page webapps is super useful.

You can see how caching strategies affect load times and also make sure you're not causing speed regressions over time. When you're working on localhost or fast internet you may do things that seem like acceptable speed tradeoffs that actually are significantly more impactful for your users who may be on slower connections. By having these metrics reported back from each user you can very quickly get great perspective on how your app is performing for people.

This is a very simple client side module (compatible with clientmodules and browserify) for tracking that load time and the various pieces of it and is designed to be used for reporting back to a metrics service. At &yet we send this as metadata for our "applicationLoaded" event that gets sent to (usually) mixpanel. But which one doesn't really matter, this just tracks the times and reports them.

Ultimately this approach is still flawed. The real way to do this is using the HTML5 performance API: http://www.html5rocks.com/en/tutorials/webperformance/basics/.

The trick is, it isn't basically only available in Chrome at the moment, which doesn't give us a very complete picture. So we do this for now to get some idea. I'm trying to figure out a good way to use the performance API if it exists without muddying up the data here.

Anyway, here's how it works.

How to use it

Add this bit of vanilla JS to your base HTML as high up in the <head> as you can. To get as accurate of a load start time as possible:

<!DOCTYPE html>
<script>window.times = {start: Date.now()};</script>
<script src="app.js"></script>

Then at various points that you want to track within your app's load sequence, just call recordTime() with whatever description makes sense for your app:

// require our module
var loadStats = require('loading-stats');

// for example
loadStats.recordTime('begin launch sequence');

// sometime later you may do...
loadStats.recordTime('initial data fetched');

// then get your summary and send it off to your
// metrics service. For example
mixpanel.track('web app loaded', loadStats.getSummary());

/*
the .getSummary(); method will return an object
that looks like this. With each event being miliseconds
from the start time we put in our HTML above.

{
    'begin launch sequence': 100,
    'begin launch sequence': 323,
    'fully loaded': 431
}
*/

There's also a recordStat that just takes a name/value. Say you want to count bytes of initial data or something.

var loadStats = require('loading-stats');

// this just adds it in so when you call .getSummary()
// this will be listed in there too. 
loadStats.recordStat('number of teams', teams.length);

This is useful since additional stats about the amount of data we're pulling down or if they're a power user who has gobs of data, that will help give context to and explain the longer load times.

Getting real stats in the wild is awesome

yup.

Installing

npm i loading-stats

Add it to your clientmodules or user browserify to include it in your app. voila!

Feedback

If you dig it, follow @HenrikJoreteg on the twitterwebs. If not, file issues or send pull requests :)

License

MIT

loading-stats's People

Contributors

henrikjoreteg avatar

Watchers

James Cloos avatar User 01 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.