surfnperf 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/app/views/surfnperf/_head.html.erb +17 -0
- data/vendor/assets/javascripts/surfnperf.js +46 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e499ab1d6b9b7d29973f1e10d460d421321cfb9
|
4
|
+
data.tar.gz: 1fcf4b9dd3948674360a60ec588978dafd2b227a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cde83613540a1fefe3e35aa643468fd7b49e5097c32aaa1494b15b84a4e3955865452ab67237feb7254e572b546425f78f80b4355f80dfcb74733e362600756
|
7
|
+
data.tar.gz: f5a81ee7bd8296abd6968fd9f2f3306c6e3d761c76aa5fb1bf7330fd013b78deea3f798bf8a8e3de2713b1554e6a7120f189fa8bb5761976519b88bf10c76e8e
|
data/README.md
CHANGED
@@ -49,11 +49,26 @@ There are 2 pieces of code that need to be included in your webpage:
|
|
49
49
|
}
|
50
50
|
};
|
51
51
|
|
52
|
+
SURF_N_PERF.setFirstPaint = function() {
|
53
|
+
SURF_N_PERF.marks.firstPaintFrame = (new Date()).getTime();
|
54
|
+
|
55
|
+
if(window.performance && window.performance.now) {
|
56
|
+
SURF_N_PERF.highResMarks.firstPaintFrame = window.performance.now();
|
57
|
+
|
58
|
+
if(window.performance.mark) {
|
59
|
+
window.performance.mark('firstPaintFrame');
|
60
|
+
}
|
61
|
+
}
|
62
|
+
};
|
63
|
+
|
52
64
|
if(window.addEventListener) {
|
53
65
|
window.addEventListener('load', SURF_N_PERF.setPageLoad, false);
|
54
66
|
} else {
|
55
67
|
window.attachEvent('onload', SURF_N_PERF.setPageLoad);
|
56
68
|
}
|
69
|
+
if (window.requestAnimationFrame) {
|
70
|
+
window.requestAnimationFrame(SURF_N_PERF.setFirstPaint);
|
71
|
+
}
|
57
72
|
</script>
|
58
73
|
```
|
59
74
|
|
@@ -62,6 +77,7 @@ That provides support for the following:
|
|
62
77
|
- "pageStart" marks for browsers that support [High Resolution Time](http://www.w3.org/TR/hr-time/) and/or [User Timing](http://www.w3.org/TR/user-timing/) so that "pageStart" can be used as a consistent starting point for duration calculations across all browsers regardless of their supported features
|
63
78
|
- A "loadEventEnd" mark for browsers that do not support [Navigation Timing](http://www.w3.org/TR/navigation-timing/) which can be used to compute durations from when the load event of the document is completed ([loadEventEnd](http://www.w3.org/TR/navigation-timing/#dom-performancetiming-loadend))
|
64
79
|
- A "loadEventEnd" [DOMHighResTimeStamp](http://www.w3.org/TR/hr-time/#sec-DOMHighResTimeStamp) mark for calculating high resolution durations between a Navigation Timing mark and a user mark in browsers that support [High Resolution Time](http://www.w3.org/TR/hr-time/) but don't support [User Timing](http://www.w3.org/TR/user-timing/)
|
80
|
+
- A "firstPaintFrame" mark (available in the best possible format for the browser, either a [User Timing Mark](http://www.w3.org/TR/user-timing/#performancemark), [DOMHighResTimeStamp](http://www.w3.org/TR/hr-time/#sec-DOMHighResTimeStamp), or [DOMTimeStamp](https://developer.mozilla.org/en-US/docs/Web/API/DOMTimeStamp)) that approximates the Time To First Paint in browsers that [support `window.requestAnimationFrame`](http://caniuse.com/#feat=requestanimationframe).
|
65
81
|
|
66
82
|
**2.** Then just drop the [surfnperf.min.js](https://github.com/Comcast/Surf-N-Perf/blob/master/surfnperf.min.js) in your codebase and reference that JavaScript file in your HTML document. If you're using [RequireJS](http://requirejs.org/) or [Browserify](http://browserify.org/), it registers itself as 'surfnperf'.
|
67
83
|
|
@@ -23,9 +23,26 @@
|
|
23
23
|
}
|
24
24
|
};
|
25
25
|
|
26
|
+
SURF_N_PERF.setFirstPaint = function() {
|
27
|
+
SURF_N_PERF.marks.firstPaintFrame = (new Date()).getTime();
|
28
|
+
|
29
|
+
if(window.performance && window.performance.now) {
|
30
|
+
SURF_N_PERF.highResMarks.firstPaintFrame = window.performance.now();
|
31
|
+
|
32
|
+
if(window.performance.mark) {
|
33
|
+
window.performance.mark('firstPaintFrame');
|
34
|
+
}
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
26
38
|
if(window.addEventListener) {
|
27
39
|
window.addEventListener('load', SURF_N_PERF.setPageLoad, false);
|
28
40
|
} else {
|
29
41
|
window.attachEvent('onload', SURF_N_PERF.setPageLoad);
|
30
42
|
}
|
43
|
+
|
44
|
+
if (window.requestAnimationFrame) {
|
45
|
+
window.requestAnimationFrame(SURF_N_PERF.setFirstPaint);
|
46
|
+
}
|
47
|
+
|
31
48
|
</script>
|
@@ -356,6 +356,52 @@
|
|
356
356
|
return this.duration('navigationStart', 'loadEventEnd');
|
357
357
|
};
|
358
358
|
|
359
|
+
/**
|
360
|
+
* Time to first paint (browser-reported time for the first pixels to be rendered on the page)
|
361
|
+
*
|
362
|
+
* @returns {integer} time in ms
|
363
|
+
* @memberOf SurfNPerf
|
364
|
+
*/
|
365
|
+
SNPProto.getFirstPaint = function(options) {
|
366
|
+
if(this.chromeLoadTimes()) {
|
367
|
+
return this._roundedDuration(this.getTimingMark('navigationStart', 'DOM'), this.chromeLoadTimes().firstPaintTime * 1000, options);
|
368
|
+
} else if(this.msFirstPaint()) {
|
369
|
+
return this._roundedDuration(this.getTimingMark('navigationStart', 'DOM'), this.msFirstPaint(), options);
|
370
|
+
} else {
|
371
|
+
return null;
|
372
|
+
}
|
373
|
+
};
|
374
|
+
|
375
|
+
/**
|
376
|
+
* Time to first paint (Time calculated based on window.requestAnimationFrame() for the first pixels to be rendered on the page)
|
377
|
+
*
|
378
|
+
* @returns {integer} time in ms
|
379
|
+
* @memberOf SurfNPerf
|
380
|
+
*/
|
381
|
+
SNPProto.getFirstPaintFrame = function(options) {
|
382
|
+
if(window.requestAnimationFrame) {
|
383
|
+
return this.duration('navigationStart', 'firstPaintFrame', options);
|
384
|
+
} else {
|
385
|
+
return null;
|
386
|
+
}
|
387
|
+
};
|
388
|
+
|
389
|
+
SNPProto.chromeLoadTimes = function() {
|
390
|
+
if(window.chrome && window.chrome.loadTimes) {
|
391
|
+
return window.chrome.loadTimes();
|
392
|
+
} else {
|
393
|
+
return undefined;
|
394
|
+
}
|
395
|
+
};
|
396
|
+
|
397
|
+
SNPProto.msFirstPaint = function() {
|
398
|
+
if(window.performance && window.performance.timing && window.performance.timing.msFirstPaint) {
|
399
|
+
return window.performance.timing.msFirstPaint;
|
400
|
+
} else {
|
401
|
+
return undefined;
|
402
|
+
}
|
403
|
+
};
|
404
|
+
|
359
405
|
return new SurfNPerf();
|
360
406
|
|
361
407
|
}));
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surfnperf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Riviello
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|