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

Prioritize the module loader script with link headers #203

Merged
merged 2 commits into from
Dec 18, 2017

Conversation

vigneshshanmugam
Copy link
Collaborator

screen shot 2017-12-14 at 14 38 49

Link to the bug - bugs.chromium.org/p/chromium/issues/detail?id=794958

  • With this fix, loader script should be the first to be requested, Check before and after

Before
screen shot 2017-12-17 at 18 52 55

After
screen shot 2017-12-17 at 18 51 46

Works only in prime cache because of the chrome bug.

tests/tailor.js Outdated
);
})
.then(done, done);
});

it('"shouldn\'t send preloading headers if primary fragment doesn\'t exist"', done => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -249,7 +249,6 @@ describe('Tailor', () => {
.then(response => {
assert.equal(response.statusCode, 200);
assert.deepEqual(response.headers['set-cookie'], [cookie]);
assert.equal(response.headers.link, 'http://link');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Disallow primary fragments from overriding link headers since primary fragments have no context of module loading and piping mechanism.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are also including their assets after the loader asset.

@codecov
Copy link

codecov bot commented Dec 17, 2017

Codecov Report

Merging #203 into master will increase coverage by 0.04%.
The diff coverage is 98.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #203      +/-   ##
==========================================
+ Coverage   98.29%   98.34%   +0.04%     
==========================================
  Files          14       15       +1     
  Lines         586      603      +17     
  Branches      106      112       +6     
==========================================
+ Hits          576      593      +17     
  Misses         10       10
Impacted Files Coverage Δ
lib/request-handler.js 98.8% <100%> (-0.25%) ⬇️
lib/process-template.js 100% <100%> (ø) ⬆️
lib/utils.js 100% <100%> (ø)
index.js 76.92% <66.66%> (+0.6%) ⬆️

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 7f7c263...00078e0. Read the comment docs.

lib/utils.js Outdated
host,
asAttribute,
corsCheck = false,
noPush = true // Disable HTTP/2 Push behaviour for now
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will be enabled in future once cache digests spec is implemented in browsers.

Copy link
Contributor

@mo-gr mo-gr Dec 18, 2017

Choose a reason for hiding this comment

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

Then maybe replace the for now with until digest spec is implemented by most browsers to help future maintainers. This PR commit won't be easily findable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do.


// Loader script must be preloaded before every fragment asset
const loaderScript = getLoaderScript(amdLoaderUrl, request.headers);
loaderScript !== '' && assetsToPreload.unshift(loaderScript);
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason not to use explicit if () {} 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.

To avoid the typecasting.

amdLoaderUrl,
request.headers
);
loaderScript !== '' &&
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason not to use explicit if () {} here?

lib/utils.js Outdated
const LinkHeader = require('http-link-header');

const getCrossOrigin = (url = '', host) => {
if (host && url.indexOf(`://${host}`) < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

url.includes(...) is a tiny bit more expressive

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@mo-gr
Copy link
Contributor

mo-gr commented Dec 18, 2017

👍

1 similar comment
@vigneshshanmugam
Copy link
Collaborator Author

👍

@vigneshshanmugam vigneshshanmugam merged commit a2124ea into master Dec 18, 2017
@vigneshshanmugam vigneshshanmugam deleted the prioritize-loader branch December 18, 2017 13:15
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.

preload the module loader script to avoid getting deprioritized
2 participants