Skip to content
This repository was archived by the owner on May 17, 2019. It is now read-only.

Conversation

rtsao
Copy link
Contributor

@rtsao rtsao commented Oct 1, 2018

Per https://developers.google.com/web/updates/2017/12/modulepreload preload hints must be using the same credentials mode as the script tags for there to be a cache hit.

This PR ensures that preload hints have the same crossorigin attribute as the script tags to prevent double fetching.

@rtsao rtsao added the bugfix label Oct 1, 2018
@codecov
Copy link

codecov bot commented Oct 1, 2018

Codecov Report

Merging #314 into master will increase coverage by 0.21%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #314      +/-   ##
==========================================
+ Coverage    91.4%   91.62%   +0.21%     
==========================================
  Files          18       18              
  Lines         419      418       -1     
  Branches       83       81       -2     
==========================================
  Hits          383      383              
  Misses         22       22              
+ Partials       14       13       -1
Impacted Files Coverage Δ
src/plugins/ssr.js 90.47% <88.88%> (+1.41%) ⬆️

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 650726b...d0cea6b. Read the comment docs.

@rtsao
Copy link
Contributor Author

rtsao commented Oct 1, 2018

!merge

@old-fusion-bot old-fusion-bot bot merged commit 7fc464d into master Oct 1, 2018
@alxmyth alxmyth mentioned this pull request Oct 2, 2018
@mlmorg
Copy link

mlmorg commented Oct 2, 2018

Is it possible to write a test for this?

@rtsao
Copy link
Contributor Author

rtsao commented Oct 2, 2018

Yeah, to test this I would:

  • Produce a production build from a fixture app w/ fusion-cli
  • Start a separate static asset server for client chunks on a different port
  • Start the production build w/ CDN_URL env set to the static asset server
  • Start puppeteer and assert on "request" events to ensure chunk requests aren't duplicated

A less good test might be to simply assert on ctx.body and ensure crossorigin attributes are the same for preload hints as well as scripts when CDN_URL is used. This test would be quicker to implement but I think has dubious value.

Either way, preload hints are only present in the legacy body template, which will be deleted in the next major version. The new template lives in fusion-cli, added in (fusionjs/fusion-cli#531), which doesn't have preload hints because they won't work with the future <script type="module"> and <script nomodule> loading strategy.

For the sake of expediency in getting a pre-release out, I verified this fix in a production app but didn't write a proper test since this codepath has already been replaced. An issue for adding a regression test: #317

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.

3 participants