-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 174538f
Showing
46 changed files
with
4,085 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"directory": "test/vendor", | ||
"color" : false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"amd": true | ||
}, | ||
"rules": { | ||
// | ||
// v1.0 rules | ||
// | ||
"camelcase": 2, | ||
"comma-spacing": 2, | ||
"consistent-return": 2, | ||
"curly": [2, "all"], | ||
"dot-notation": [2, { "allowKeywords": true }], | ||
"eol-last": 2, | ||
"eqeqeq": 2, | ||
"key-spacing": [2, { "beforeColon": false, "afterColon": true }], | ||
"new-cap": 2, | ||
"new-parens": 2, | ||
"no-alert": 2, | ||
"no-array-constructor": 2, | ||
"no-caller": 2, | ||
"no-catch-shadow": 2, | ||
"no-empty-label": 2, | ||
"no-eval": 2, | ||
"no-extend-native": 2, | ||
"no-extra-bind": 2, | ||
"no-extra-parens": [2, "functions"], | ||
"no-implied-eval": 2, | ||
"no-iterator": 2, | ||
"no-label-var": 2, | ||
"no-labels": 2, | ||
"no-lone-blocks": 2, | ||
"no-loop-func": 2, | ||
"no-multi-spaces": 2, | ||
"no-multi-str": 2, | ||
"no-native-reassign": 2, | ||
"no-new": 2, | ||
"no-new-func": 2, | ||
"no-new-object": 2, | ||
"no-new-wrappers": 2, | ||
"no-octal-escape": 2, | ||
"no-process-exit": 2, | ||
"no-proto": 2, | ||
"no-return-assign": 2, | ||
"no-script-url": 2, | ||
"no-sequences": 2, | ||
"no-shadow": 2, | ||
"no-shadow-restricted-names": 2, | ||
"no-spaced-func": 2, | ||
"no-trailing-spaces": 2, | ||
"no-undef-init": 2, | ||
"no-underscore-dangle": 2, | ||
"no-unused-expressions": 2, | ||
"no-use-before-define": 2, | ||
"no-with": 2, | ||
"quotes": [2, "double"], | ||
"semi": 2, | ||
"semi-spacing": [2, {"before": false, "after": true}], | ||
"space-infix-ops": 2, | ||
"space-return-throw-case": 2, | ||
"space-unary-ops": [2, { "words": true, "nonwords": false }], | ||
"strict": [2, "function"], | ||
"yoda": [2, "never"], | ||
|
||
// | ||
// Enabled over default | ||
// | ||
"valid-jsdoc": [1, { | ||
"requireReturn": false, | ||
"prefer": { | ||
"return": "returns" | ||
} | ||
}], | ||
"guard-for-in": 2, | ||
"no-div-regex": 2, | ||
"no-eq-null": 2, | ||
"no-floating-decimal": 2, | ||
"no-self-compare": 2, | ||
"no-void": 2, | ||
"radix": 2, | ||
"wrap-iife": 2, | ||
"no-mixed-requires": 2, | ||
"no-new-require": 2, | ||
"no-path-concat": 2, | ||
"brace-style": [2, "1tbs", { "allowSingleLine": false }], | ||
"comma-style": [2, "last"], | ||
"consistent-this": [2, "that"], | ||
"no-inline-comments": 2, | ||
"no-multiple-empty-lines": [1, {"max": 1}], | ||
"no-nested-ternary": 2, | ||
"space-before-function-paren": [2, "never"], | ||
"space-after-keywords": 1, | ||
"space-before-blocks": 1, | ||
"space-in-parens": 1, | ||
"space-unary-ops": 1, | ||
"spaced-comment": 1, | ||
"max-len": [1, 120, 4], | ||
|
||
// | ||
// Disabled | ||
// | ||
"no-loop-func": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/node_modules | ||
.project | ||
.settings/ | ||
npm-debug.log | ||
/eslint.xml | ||
/test/*.tap | ||
/test/coverage | ||
/test/vendor | ||
/test/build/data.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.bowerrc | ||
.eslintrc | ||
.gitmodules | ||
.npmignore | ||
.travis.yml | ||
gulpfile.js | ||
bower.json | ||
dist | ||
karma.config.js | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: node_js | ||
node_js: | ||
- "5" | ||
- "4" | ||
- "0.12" | ||
- "0.11" | ||
- "0.10" | ||
before_install: npm install -g gulp | ||
script: gulp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2015 Nic Jansma, http://nicj.net | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
# usertiming-compression.js | ||
|
||
v0.1.0 | ||
|
||
[http://nicj.net](http://nicj.net) | ||
|
||
Licensed under the MIT license | ||
|
||
## Introduction | ||
|
||
`usertiming-compression.js` compresses data from [UserTiming](http://www.w3.org/TR/user-timing/). A | ||
companion script, `usertiming-decompression.js`, converts the compressed data back to the original form. | ||
|
||
[UserTiming](http://www.w3.org/TR/user-timing/) is a [modern browser](http://caniuse.com/#feat=user-timing) performance API that gives developers the ability the mark important events (timestamps) and measure durations (timestamp deltas) in their web apps. The [PerformanceTimeline](http://www.w3.org/TR/performance-timeline/) has several methods such as | ||
`performance.getEntriesByType('mark')` or `performance.getEntriesByType('measure')` that return each mark or measure's `startTime` (timestamp) and `duration` (for measures). | ||
|
||
`usertiming-compression.js` applies several data-compression techniques to reduce the size of your serialized | ||
UserTiming data to 10-15% of it's original size in many cases. See | ||
[this blog post](http://nicj.net/compressing-usertiming/) for a description of these techniques. | ||
|
||
`usertiming-decompression.js` is a companion script that will take the compressed UserTiming data and | ||
build it back to its original UserTiming form (eg. `performance.getEntriesByType('mark')`) for analysis. | ||
|
||
## Download | ||
|
||
Releases are available for download from [GitHub](https://github.com/nicjansma/usertiming-compression.js). | ||
|
||
### Web - Compression | ||
|
||
__Development:__ [usertiming-compression.js](https://github.com/nicjansma/usertiming-compression.js/raw/master/src/usertiming-compression.js) - 19kb | ||
|
||
__Production:__ [usertiming-compression.min.js](https://github.com/nicjansma/usertiming-compression.js/raw/master/dist/usertiming-compression.min.js) - 3.9kb minified, 1.6kb gzipped | ||
|
||
### Web - Decompression | ||
|
||
__Development:__ [usertiming-decompression.js](https://github.com/nicjansma/usertiming-compression.js/raw/master/src/usertiming-decompression.js) - 15.9kb | ||
|
||
__Production:__ [usertiming-decompression.min.js](https://github.com/nicjansma/usertiming-compression.js/raw/master/dist/usertiming-decompression.min.js) - 3.7kb minified, 1.5kb gzipped | ||
|
||
### NPM | ||
|
||
usertiming-compression.js is also available as the [npm usertiming-compression module](https://npmjs.org/package/usertiming-compression). You can install | ||
using Node Package Manager (npm): | ||
|
||
npm install usertiming-compression | ||
|
||
### Bower | ||
|
||
usertiming-compression.js is also available via [bower](http://bower.io/). You can install using: | ||
|
||
bower install usertiming-compression | ||
|
||
## Usage | ||
|
||
Please see the [W3C UserTiming API Reference](http://www.w3.org/TR/user-timing/) for details on how to use the | ||
UserTiming API. | ||
|
||
### usertiming-compression.js | ||
|
||
To include usertiming-compression.js, include it via a script tag: | ||
|
||
```html | ||
<script type="text/javascript" src="usertiming-compression.min.js"></script> | ||
``` | ||
|
||
Once included in the page, a top-level `UserTimingCompression` object is available on `window`. If AMD or CommonJS environments are detected, it will expose itself via those methods. | ||
|
||
From the NPM module: | ||
|
||
```js | ||
var UserTimingCompression = require("usertiming-compression").UserTimingCompression; | ||
``` | ||
|
||
To get a map of compressed UserTiming names to values, you can call: | ||
|
||
```js | ||
var utMap = UserTimingCompression.getCompressedUserTiming(options); | ||
// { | ||
// "mark1": "2s", | ||
// "mark2": "5k", | ||
// "mark3": "8c" | ||
// } | ||
``` | ||
|
||
If you have a [map](http://nicj.net/compressing-usertiming/) of mark / measure names you want to use, pass them in as `options.map`: | ||
|
||
```js | ||
var utMap = UserTimingCompression.getCompressedUserTiming({ | ||
map: { | ||
"mark1": 0, | ||
"mark2": 1, | ||
"mark3": 2 | ||
} | ||
}); | ||
// { | ||
// "0": "2s", | ||
// "1": "5k", | ||
// "2": "8c" | ||
// } | ||
``` | ||
|
||
If you want to further compress this list for a format suitable for URL transmission (e.g. on a query string), you can use `compressForUri()`: | ||
|
||
```js | ||
var utData = UserTimingCompression.compressForUri(utMap); | ||
// ~(m~(ark~(1~'2s~2~'5k~3~'8c))) | ||
``` | ||
|
||
### API | ||
|
||
#### `UserTimingCompression.getCompressedUserTiming(options)` | ||
|
||
Gathers all UserTiming marks and measures from the root HTML page and all accessible IFRAMEs. | ||
|
||
**Arguments**: | ||
* `options` (optional) | ||
* `options.map`: A map of names to indexes to use for compression. | ||
* `options.from`: The minimum `startTime` | ||
* `options.to`: The maximum `startTime` | ||
|
||
**Returns**: A map of names to compressed values. | ||
|
||
```js | ||
{ | ||
"mark1": "2s", | ||
"mark2": "5k", | ||
"mark3": "8c" | ||
} | ||
``` | ||
|
||
#### `UserTimingCompression.compressForUri(map)` | ||
|
||
Takes the output of `getCompressedUserTiming()` and converts it into a string suitable for URI encoding. | ||
|
||
**Arguments**: | ||
* `map` A map of names to string values | ||
|
||
**Returns**: A map of names to compressed values. | ||
|
||
``` | ||
"~(m~(ark~(1~'2s~2~'5k~3~'8c)))" | ||
``` | ||
|
||
**Note**: The first character of the string denotes what type of [compression](http://nicj.net/compressing-usertiming/) is used: | ||
|
||
1. `~` is optimized Trie (JSURL) compression | ||
2. `0` is a tilde array | ||
3. `1` is a mapped array | ||
|
||
### usertiming-decompression.js | ||
|
||
To include usertiming-decompression.js, include it via a script tag: | ||
|
||
```html | ||
<script type="text/javascript" src="usertiming-decompression.min.js"></script> | ||
``` | ||
|
||
Once included in the page, a top-level `UserTimingDecompression` object is available on `window`. If AMD or CommonJS environments are detected, it will expose itself via those methods. | ||
|
||
From the NPM module: | ||
|
||
```js | ||
var UserTimingDecompression = require("usertiming-compression").UserTimingDecompression; | ||
``` | ||
|
||
To decompress your resources, you can call: | ||
|
||
```js | ||
var original = UserTimingDecompression.decompressUserTiming(utData); | ||
``` | ||
|
||
### API | ||
|
||
#### `UserTimingDecompression.decompressUserTiming(data)` | ||
|
||
Decompresses data from a URI-encoded form. | ||
|
||
**Arguments**: | ||
* `data` Data compressed via `compressForUri()` | ||
|
||
**Returns**: The original UserTiming data | ||
|
||
```js | ||
[ | ||
{"duration":0,"entryType":"mark","name":"mark1","startTime":100}, | ||
{"duration":0,"entryType":"mark","name":"mark1","startTime":150}, | ||
{"duration":0,"entryType":"mark","name":"mark1","startTime":500} | ||
] | ||
``` | ||
|
||
## Tests | ||
|
||
Tests are provided in the ``test/`` directory, and can be run via ``mocha``: | ||
|
||
mocha test/* | ||
|
||
Or via ``gulp``: | ||
|
||
gulp test | ||
|
||
## Version History | ||
|
||
* v0.1.0 - 2015-12-10: Initial version | ||
|
||
## Thanks | ||
|
||
Parts of [JSURL](https://github.com/Sage/jsurl) were incorporated into this library. This project builds upon the work of [ResourceTiming Compression](https://github.com/nicjansma/resourcetiming-compression.js), with guidance from [Philip Tellis](http://bluesmoon.info/) and others at [SOASTA](http://www.soasta.com). |
Oops, something went wrong.