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

fix issue with preloading wrong assets on pages #141

Merged
merged 2 commits into from
Apr 12, 2017
Merged

Conversation

vigneshshanmugam
Copy link
Collaborator

  • The old way of preloading logic is buggy and creates sync issues because it was based on events.

This is cleaner approach and fixes the issue with preloading wrong assets for previously rendered page. This scenario is hard to test because of the way events work and you would need to loadtest the system to really create this scenario.

@codecov-io
Copy link

codecov-io commented Apr 11, 2017

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff            @@
##             master    #141   +/-   ##
========================================
  Coverage          ?   92.3%           
========================================
  Files             ?      13           
  Lines             ?     507           
  Branches          ?      89           
========================================
  Hits              ?     468           
  Misses            ?      39           
  Partials          ?       0
Impacted Files Coverage Δ
lib/request-handler.js 96.96% <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 f6114fe...142c39f. Read the comment docs.

return assetsToPreload;
}
if (links.stylesheet && links.stylesheet.url) {
assetsToPreload += `<${links.stylesheet.url}>; rel="preload"; as="style"; nopush,`;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we might end up with a dangling comma here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you mean? We need the comma between two preloaded assets.

Copy link

Choose a reason for hiding this comment

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

Probably a trailing comma when the primary fragment doesn't have a JS?

Copy link

Choose a reason for hiding this comment

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

But it's the existing 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 and browsers does ignore it.. Don't think we need to do anything here. Thoughts?

@@ -118,7 +109,10 @@ module.exports = function processRequest (options, request, response) {
}
this.emit('response', request, statusCode, responseHeaders);
// Make resources early discoverable while processing HTML
assetsToPreload && response.setHeader('Link', assetsToPreload);
let preloadAssets = getAssetsToPreload(headers, request);
Copy link

Choose a reason for hiding this comment

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

This can be const.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, thought I had a config for eslint to capture this case.

@vigneshshanmugam vigneshshanmugam merged commit afbc5ea into master Apr 12, 2017
@vigneshshanmugam vigneshshanmugam deleted the fix-preload branch April 12, 2017 08:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants