-
Notifications
You must be signed in to change notification settings - Fork 140
(perf): improve parsing of link header from fragments #248
Conversation
vigneshshanmugam
commented
Aug 12, 2018
•
edited
Loading
edited
- Roll our own fine tuned parse link header implementation based on https://github.com/thlorenz/parse-link-header
- Avoid double parsing of link headers on fragment response and while preloading
- Keep fragment object shape static
Codecov Report
@@ Coverage Diff @@
## master #248 +/- ##
=========================================
Coverage ? 99.54%
=========================================
Files ? 17
Lines ? 658
Branches ? 124
=========================================
Hits ? 655
Misses ? 3
Partials ? 0
Continue to review full report at Codecov.
|
lib/utils.js
Outdated
@@ -80,6 +68,20 @@ const getFragmentAssetsToPreload = (headers, { host } = {}) => { | |||
return assetsToPreload; | |||
}; | |||
|
|||
function getFragmentAssetUris(refs, assetSize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Why put this in utils, is it used anywhere else?
Are we planning to add this to the exported API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, I can move inside fragment.js
assert.deepStrictEqual(parseLinkHeader(linkHeader), []); | ||
}); | ||
|
||
it('filters invalid rel attributes', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is an invalid rel attr?
Empty? Can I use in rel="styleshit"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ofcourse you can lol. its valid. But wont be loaded because of the check in getFragmentAssetUris.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the test if for rel="" and no rel attribute at all. do you have any better naming suggestion if its confusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it could be rephrased... but it is fine.
const styleUris = []; | ||
|
||
for (const ref of refs) { | ||
if (ref.rel === 'fragment-script') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have tests for this filtering behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, tests/tailor.js.
👍 |
1 similar comment
👍 |