Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

(perf): improve parsing of link header from fragments #248

Merged
merged 2 commits into from
Aug 12, 2018

Conversation

vigneshshanmugam
Copy link
Collaborator

@vigneshshanmugam vigneshshanmugam commented Aug 12, 2018

  • 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
Copy link

codecov bot commented Aug 12, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@d05e816). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #248   +/-   ##
=========================================
  Coverage          ?   99.54%           
=========================================
  Files             ?       17           
  Lines             ?      658           
  Branches          ?      124           
=========================================
  Hits              ?      655           
  Misses            ?        3           
  Partials          ?        0
Impacted Files Coverage Δ
lib/request-handler.js 99% <100%> (ø)
lib/parse-link-header.js 100% <100%> (ø)
lib/fragment.js 100% <100%> (ø)
lib/utils.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d05e816...032abda. Read the comment docs.

lib/utils.js Outdated
@@ -80,6 +68,20 @@ const getFragmentAssetsToPreload = (headers, { host } = {}) => {
return assetsToPreload;
};

function getFragmentAssetUris(refs, assetSize) {
Copy link
Contributor

@ruiaraujo ruiaraujo Aug 12, 2018

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?

Copy link
Collaborator Author

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', () => {
Copy link
Contributor

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"?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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?

Copy link
Contributor

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') {
Copy link
Contributor

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, tests/tailor.js.

@ruiaraujo
Copy link
Contributor

👍

1 similar comment
@vigneshshanmugam
Copy link
Collaborator Author

👍

@vigneshshanmugam vigneshshanmugam merged commit 6e58b8f into master Aug 12, 2018
@vigneshshanmugam vigneshshanmugam deleted the perf-1 branch August 12, 2018 15:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants