Giter Club home page Giter Club logo

justice's Introduction

Justice.js

ScreenShot Justice will create an on page toolbar that displays page timing metrics and a streaming fps meter. Budgets are also supported for timing metrics. > DEMO <

Budget results are color coded based on budgets:

  • Over budget: Red
  • 80% budget: Yellow

  • Under budget: Green

The FPS meter does not support budgets at this time but does color code the spline (or optional dot type) chart, assuming a goal of 60 FPS.

The "requests" metric also supports budgets and is unique in that it polls for changes to that metric over time, since most webpages these days load a boat load of stuff async after page load. In the future it would be possible to seperate this metric into "Sync Requests" and "Async Requests". But not right now.

The tiny button in the lower right hand corner is a simple hide show with localstorage persistance.

** Justice is under active development and the API may change. **

Why

The goal of this project is to provide insight into the performance of a webpage. I would refer to it as a "high level performance discovery tool". My vision for the tool is to allow developers, support team members and anyone interested to discover troublesome performance issues that might not have been previously known. Networks like Vox Media for instance, have many data, media and page types which could end up being manifested in many different combinations. Justice can be rolled out to authenticated users so they can become more aware of perf as they browse their own sites and applications.

Once a page shows signs of performance issues, next steps would likely include recording the performance violation and escalating investigation into the whys - using more robust tools like Chromes dev tools or whatever the team is using for deep performance debugging.

I am considering adding a reporting agent to make recording violations easier, which would probably be an optional callback provided to the Justice initializer. Then one could push the violation data set to some arbitrary endpoint.

Use

Simple

<script type="text/javascript" src="../build/justice.mapped.min.js"></script>
<script type="text/javascript">
  Justice.init();
</script>

With options

<script type="text/javascript" src="../build/justice.mapped.min.js"></script>
<script type="text/javascript">
    Justice.init({
      metrics: {
        pageLoad: { budget: 200 },
        domComplete: { budget: 800 },
        domInteractive: { budget: 200 },
        requests: { budget: 6 }
      },

      warnThreshold: 0.70,
      showFPS: true,
      chartType: 'spline'
    });
</script>

Develop

The default grunt process will watch files for changes and handle builds. I keep examples/simple.html open in a browser, which will automatically be refreshed on build.

npm install
grunt

I like to keep an eye on fill size, so you can additionally watch that.

watch tail log/size-log.txt

Contribute

Pull requests are always welcome. Before you plan a PR, please ensure the values and functionality listed below will be maintained with your PR.

Checkout the to do list: https://waffle.io/okor/justice

Core Values:

  • Easily embeddable
  • No dependencies
  • As small as possible
  • Render itself at 60fps or greater

Core Functionality:

  • Load times
  • FPS
  • works in modern browsers + graceful failure [TODO]

Roadmap

  • console.log'ish proxy
  • window on error log
  • bookmarklet
  • cdn.js release
  • npm release
  • chrome plugin

Release versioning

  • <major>.<minor>.<patch>, ex: 0.1.8

justice's People

Contributors

bronzehedwick avatar homaily avatar kendrick-k avatar kennyt avatar okor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

justice's Issues

Background Changes

Might be nice to be able to change some of the looks of the toolbar. Background colour and text colour changes for example?

Thanks!

Idea for a console proxy

Hello,

I'd like to contribute some code for the console proxy feature.

console = {
    justice: document.getElementById('justice'),
    lines: 0,
    writeLine: function (type, msg) {
        var line = document.createElement('div');
          
        line.classList.add('justice-console');        
        line.style.color = '#fff';
        line.style.width = '100%';
        line.textContent = this.lines + ': ' + msg;
        this.justice.appendChild(line);
        this.lines++;
    },
    log: function (msg) {
        this.writeLine('log', msg);
    },
    info: function (msg) {
        this.writeLine('info', msg);
    },
    warn: function (msg) {
        this.writeLine('warn', msg);
    },
    error: function (msg) {
        this.writeLine('error', msg);
    }
}

Maybe this is helpful, I could finish the feature by myself with a API documentation :-)

domContentLoaded vs. window.chrome.loadTimes().firstPaintTime

Hi,
First just want to say I really like this plugin and find it useful. It gives really easy access to important metrics.

I'm trying to investigate critical rendering and I was wondering how firstPaintTime compares to domContentLoaded and why you are using firstPaintTime and domContentComplete, but not domContentLoaded.

Does firstPaintTime actually match critical render or is just when something happens when anything starts to be painted on the screen? I've tried to find some docs on firstPaintTime but can't find anything specific and what it indicates.

On google's page regarding critical rendering time, it doesn't reference the paint time.
https://developers.google.com/web/fundamentals/performance/critical-rendering-path/measure-crp?hl=en

For example, what would be the difference between what these two indicate?

1:
((window.chrome.loadTimes().firstPaintTime * 1000) - (window.chrome.loadTimes().startLoadTime*1000)).toFixed(0);

2:
(window.performance.timing.domContentLoadedEventStart - window.performance.timing.domLoading)

Do you know which one of these would be closer to critical rendering time?

Shim strat

We might be able to add shims but I'm in favor of just reporting what the browser is capable of handling. Think about it.

Errors when viewing demo in Safari 6.2.4

I went to http://okor.github.io/justice/ in Safari and did not see the expected metric bar. The following errors were in the console:

[Error] TypeError: undefined is not an object (evaluating 'window.performance.timing')
    (anonymous function) (justice.min.js, line 1)
    global code (justice.min.js, line 1)
[Error] TypeError: undefined is not an object (evaluating 'Justice.init')
    global code (justice, line 93)

OS X 10.8.5
Safari 6.2.4

If browsers don't support window.performance Justice should fail gracefully.

bookmarklet

๐Ÿ‘ for the bookmarklet in your roadmap!
That would proof very handy!!

Still active?

Hey @okor!

I plan on doing some work on this, because we want to use it at @Lostmyname. If I send pull requests, will you deal with them? Just asking because you don't seem to have been active on github for a while :)

Alternatively, would you be willing to add me as a collaborator? I can run you through a few ideas I've had to see if you approve (mostly around ES6 and bower/npm right now).

Extension point for capturing metrics

Something like this:

<script type="text/javascript">

    $(document).on("justice:metrics", function (event, metrics) {
        console.log(metrics);
        $.ajax({
            type: "POST",
            url: "/api/metrics",
            data: JSON.stringify(metrics),
            dataType: "application/json",
            success: function (result) {
                console.log(result);
            }
        });
    });

    Justice.init({
        metrics: {
            TTFB: { budget: 200 },
            domInteractive: { budget: 250 },
            domComplete: { budget: 800 },
            firstPaint: { budget: 1000 },
            pageLoad: { budget: 2000 },
            requests: { budget: 6 },
        },
        warnThreshold: 0.8,
        showFPS: true,
        chartType: 'spline'
    });

</script>

And in seriouslyInit publish metrics:

function seriouslyInit(opts) {
        timing = window.performance.timing;
        options = mergeOptions(opts);
        setActiveMetrics(options, activeMetrics, availableMetrics);
        renderUI();
        fpsRenderer = getFpsRenderer(options.chartType);
        window.requestAnimationFrame(tick);

        var metrics = [];
        for (var k in activeMetrics) {
            var metric = activeMetrics[k];
            metrics.push({
                id: metric.id,
                label: metric.label,
                unitLabel: metric.unitLabel,
                value: metric.collector()
            });
        }

        $(document).trigger("justice:metrics", [metrics]);
    }

Question: Shift in trackFPS

does

dataFpsHistory.shift()

have to reindex the 400 length array every single time it gets called? or is this not a problem?

Remote stats / custom stats

It would be rad to be able to pull in RUM metrics from GA. This may be best handled by supporting custom metrics, since everyone will have different requirements.

Default budgets

They are currently thoughtless but we should have good defaults.

Use dynamic unit labels

Currently using ms everywhere, would be great to add optional s unit. Feels like this should be an option.

Visual timeline

With limited space, this might be challenging. But it would be cool to display a simple timeline chart for various load time metrics. Might just be a 2px tall border along the top/bottom of the UI.

Theme support

Goals:

  • Share style variable between SCSS and JS.
  • Allow theme customization

Benchmarking

Anything that resides inside of tick() should be wicked fast. As part of the test suite we should ensure everything runs are 60ps or better.

More brains

I'd like to get some more eyes on this before the initial release. Sanity checks and the like.

API checks

Before moving a metric into the active queue, confirm the browser has the appropriate API available.

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.