Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to verify preload caching behavior #31539

Merged
merged 7 commits into from
Dec 1, 2021
Merged

Add tests to verify preload caching behavior #31539

merged 7 commits into from
Dec 1, 2021

Conversation

noamr
Copy link
Contributor

@noamr noamr commented Nov 8, 2021

Check that preloaded resources are reused/ignored based on the
parameters available to a preload link (href, crossorigin, as),
and do not rely on other parameters (e.g. whether a script is a module, or an image is decoded successfully).

See whatwg/html#7260
and whatwg/fetch#1342

@noamr
Copy link
Contributor Author

noamr commented Dec 1, 2021

Submitted implementation bugs:
Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=1275460
Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1743764
(having a hard time testing on Safari due to certificate issues, will attempt later)

Copy link
Contributor

@yoavweiss yoavweiss left a comment

Choose a reason for hiding this comment

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

Looks good! A couple of questions

preload/preload-invalid-resources.html Show resolved Hide resolved
<script src="/preload/resources/preload_helper.js"></script>
<script>

const crossOriginHost = 'https://{{host}}:{{ports[https][0]}}'
Copy link
Contributor

Choose a reason for hiding this comment

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

We typically use get-host-info.sub.js for those things, as it encapsulates the "sub" parts and is generally more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, originally it needed to be as a sub.html, I'll revise

for (const resourceConfigName of configNames) {
for (const preloadConfigName of Object.keys(configs)) {
if (resourceConfigName === 'same-origin' && preloadConfigName !== 'same-origin')
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: || those 2 conditions? (instead of having those separate if statements)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, we're skipping those cases because in those cases we'd get a different URL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because if it's the same origin the CORS attributes are ignored anyway. Will try to clarify with a comment

}, `Loading ${type} (${resourceConfig}) with link (${preloadConfig}) should ${expected} the preloaded response`);
}

for (const resourceTypeName in resourceTypes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

s/in/of/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's a key iteration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed to use Object.entries instead

}

const configs = {
'same-origin': {crossOrigin: false, attributes: {}},
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment saying what each of the config values does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

@noamr noamr left a comment

Choose a reason for hiding this comment

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

Fixed CR comments.

preload/preload-invalid-resources.html Show resolved Hide resolved
Copy link
Contributor

@yoavweiss yoavweiss left a comment

Choose a reason for hiding this comment

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

LGTM % nits

<script src="/common/get-host-info.sub.js"></script>
<script>

const {REMOTE_HOST, HTTPS_PORT} = get_host_info();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: you can use HTTPS_REMOTE_ORIGIN instead of those two


}

for (const resourceTypeName in resourceTypes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Leftovers?

preload/preload-invalid-resources.html Show resolved Hide resolved
noamr added 7 commits December 1, 2021 14:16
Check that preloaded resources are reused/ignored based on the
parameters available to a preload link (href, crossorigin, as),
and do not rely on other parameters (e.g. whether a script is a module).

See whatwg/html#7260
and whatwg/fetch#1342
@noamr noamr enabled auto-merge (squash) December 1, 2021 12:23
@noamr noamr merged commit ef427f5 into master Dec 1, 2021
@noamr noamr deleted the preload-cache branch December 1, 2021 12:25
annevk pushed a commit to whatwg/fetch that referenced this pull request Feb 11, 2022
Before any particular fetch steps are performed, see if there is a matching request already in the preload store and consume it.

This is called from the main fetch to avoid race conditions.

Depends on whatwg/html#7260, and together they fix #590.

Tests: web-platform-tests/wpt#31539.
ericorth pushed a commit to ericorth/fetch that referenced this pull request Feb 18, 2022
Before any particular fetch steps are performed, see if there is a matching request already in the preload store and consume it.

This is called from the main fetch to avoid race conditions.

Depends on whatwg/html#7260, and together they fix whatwg#590.

Tests: web-platform-tests/wpt#31539.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants