Skip to content

Commit

Permalink
Add new initiator types: early-hints, ping, font (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
jberner12 committed May 30, 2023
1 parent 1d6e991 commit 5ba22d7
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 11 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ INITIATOR_TYPES = {
"track": "h",
"embed": "i",
"eventsource": "j",
"navigation": 6
"navigation": 6,
"early-hints": "k",
"ping": "l",
"font": "m"
}
```

Expand Down
8 changes: 7 additions & 1 deletion src/resourcetiming-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@
/** EventSource */
"eventsource": "j",
/** The root HTML page itself */
"navigation": 6
"navigation": 6,
/** Early Hints */
"early-hints": "k",
/** HTML <a> ping Attribute */
"ping": "l",
/** CSS font at-rule */
"font": "m"
};

// Words that will be broken (by ensuring the optimized trie doesn't contain
Expand Down
18 changes: 9 additions & 9 deletions src/resourcetiming-decompression.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,19 @@
/** XMLHttpRequest */
"xmlhttprequest": 5,
/** The root HTML page itself */
"html": 6,
"navigation": 6,
/** IMAGE element inside a SVG */
"image": 7,
/** [sendBeacon]{@link https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon} */
"beacon": 8,
/** [Fetch API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API} */
"fetch": 9,
/** An IFRAME */
"iframe": "a",
/** IE11 and Edge (some versions) send "subdocument" instead of "iframe" */
"subdocument": "a",
/** FRAME element */
"frame": "a",
/** BODY element */
"body": "b",
/** INPUT element */
"input": "c",
/** FRAME element */
"frame": "a",
/** OBJECT element */
"object": "d",
/** VIDEO element */
Expand All @@ -78,8 +74,12 @@
"embed": "i",
/** EventSource */
"eventsource": "j",
/** The root HTML page itself */
"navigation": 6
/** Early Hints */
"early-hints": "k",
/** HTML <a> ping Attribute */
"ping": "l",
/** CSS font at-rule */
"font": "m"
};

/**
Expand Down
42 changes: 42 additions & 0 deletions test/test-resourcetiming-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,48 @@
servertiming: {}
});
});

it("Should compress initiatorType early-hints data", function() {
expect(ResourceTimingCompression.compressResourceTiming(null, [{
name: "foo",
initiatorType: "early-hints",
startTime: 1,
responseEnd: 2
}], { lookup: {} })).to.eql({
restiming: {
"foo": "k1,1"
},
servertiming: {}
});
});

it("Should compress initiatorType ping data", function() {
expect(ResourceTimingCompression.compressResourceTiming(null, [{
name: "foo",
initiatorType: "ping",
startTime: 1,
responseEnd: 2
}], { lookup: {} })).to.eql({
restiming: {
"foo": "l1,1"
},
servertiming: {}
});
});

it("Should compress initiatorType font data", function() {
expect(ResourceTimingCompression.compressResourceTiming(null, [{
name: "foo",
initiatorType: "font",
startTime: 1,
responseEnd: 2
}], { lookup: {} })).to.eql({
restiming: {
"foo": "m1,1"
},
servertiming: {}
});
});
});

//
Expand Down
17 changes: 17 additions & 0 deletions test/test-resourcetiming-decompression.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex(3)).to.be("script");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex(4)).to.be("css");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex(5)).to.be("xmlhttprequest");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex(6)).to.be("navigation");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex(7)).to.be("image");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex(8)).to.be("beacon");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex(9)).to.be("fetch");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("a")).to.be("frame");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("b")).to.be("body");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("c")).to.be("input");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("d")).to.be("object");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("e")).to.be("video");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("f")).to.be("audio");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("g")).to.be("source");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("h")).to.be("track");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("i")).to.be("embed");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("j")).to.be("eventsource");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("k")).to.be("early-hints");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("l")).to.be("ping");
expect(ResourceTimingDecompression.getInitiatorTypeFromIndex("m")).to.be("font");
});
});

Expand Down

0 comments on commit 5ba22d7

Please sign in to comment.