Skip to content

Commit

Permalink
v1.2.4: Added skipDimensions option
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Jul 16, 2019
1 parent 0652411 commit 6af733b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# resourcetiming-compression.js

v1.2.3
v1.2.4

[http://nicj.net](http://nicj.net)

Expand Down Expand Up @@ -253,6 +253,8 @@ Or via ``gulp``:

## Version History

* v1.2.4 - 2019-07-16
* Optional `skipDimensions` for `getResourceTiming()` and `compressResourceTiming()`
* v1.2.3 - 2019-05-09
* Decode `initiatorType` above 9 properly
* v1.2.2 - 2019-05-09
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "resourcetiming-compression",
"version": "1.2.3",
"version": "1.2.4",
"homepage": "https://github.com/nicjansma/resourcetiming-compression.js",
"authors": [
"Nic Jansma <nic@nicj.net>",
Expand Down
2 changes: 1 addition & 1 deletion dist/resourcetiming-compression.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "ResourceTiming compression and decompression",
"main": "./index.js",
"author": "Nic Jansma",
"version": "1.2.3",
"version": "1.2.4",
"repository": {
"type": "git",
"url": "http://github.com/nicjansma/resourcetiming-compression.js.git"
Expand Down
16 changes: 10 additions & 6 deletions src/resourcetiming-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,9 +932,10 @@
* @param {Window} [win] The Window
* @param {number} [from] Only get timings from
* @param {number} [to] Only get timings up to
* @param {boolean} skipDimensions Skip gathering resource dimensions
* @returns {object} Optimized performance entries trie
*/
ResourceTimingCompression.getResourceTiming = function(win, from, to) {
ResourceTimingCompression.getResourceTiming = function(win, from, to, skipDimensions) {
/* eslint no-script-url:0 */
if (typeof win === "undefined") {
win = window;
Expand All @@ -947,22 +948,25 @@
return {};
}

return ResourceTimingCompression.compressResourceTiming(win, entries, serverTiming);
return ResourceTimingCompression.compressResourceTiming(win, entries, serverTiming, skipDimensions);
};

/**
* Optimizes the specified set of performance entries.
* @param {Window} win The Window
* @param {object} entries Performance entries
* @param {object} serverTiming object containing `lookup` and `indexed`
* @param {object} serverTiming Object containing `lookup` and `indexed`
* @param {boolean} skipDimensions Skip gathering resource dimensions
* @returns {object} Optimized performance entries trie
*/
ResourceTimingCompression.compressResourceTiming = function(win, entries, serverTiming) {
ResourceTimingCompression.compressResourceTiming = function(win, entries, serverTiming, skipDimensions) {
/* eslint no-script-url:0 */
var i, e, results = {}, initiatorType, url, finalUrl, data, visibleEntries = {};

// gather visible entries on the page
visibleEntries = this.getVisibleEntries(win);
if (!skipDimensions) {
// gather visible entries on the page
visibleEntries = this.getVisibleEntries(win);
}

for (i = 0; i < entries.length; i++) {
e = entries[i];
Expand Down
26 changes: 25 additions & 1 deletion test/test-resourcetiming-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@
});

//
// .compressResourceTiming
// .getResourceTiming
//
describe(".getResourceTiming()", function() {
it("Should get an object with .restiming and .servertiming from the page", function() {
Expand Down Expand Up @@ -872,6 +872,30 @@
expect(scaledImage.naturalHeight).to.equal(1000);
expect(scaledImage.naturalWidth).to.equal(1000);
});

it("Should contain the scaled PNG image without dimensions if skipDimensions was set", function() {
if (!canGetResourceTiming()) {
return this.skip();
}

var results = ResourceTimingCompression.getResourceTiming(window, undefined, undefined, true);
var resources = ResourceTimingDecompression.decompressResources(results.restiming, results.servertiming);
var scaledImage = resources.find(function(r) {
return r.name.indexOf("?scaled") !== -1;
});

if (!scaledImage) {
// Karma won't load the image
return this.skip();
}

expect(scaledImage.height).to.be.undefined;
expect(scaledImage.width).to.be.undefined;
expect(scaledImage.x).to.be.undefined;
expect(scaledImage.y).to.be.undefined;
expect(scaledImage.naturalHeight).to.be.undefined;
expect(scaledImage.naturalWidth).to.be.undefined;
});
});
});
}(typeof window !== "undefined" ? window : undefined));

0 comments on commit 6af733b

Please sign in to comment.