New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 678429 link

Starred by 3 users

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Jan 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug



Sign in to add a comment

link rel="preload" double downloads resources loaded by imported html files

Project Member Reported by andyb...@chromium.org, Jan 4 2017

Issue description

Chrome 55.0.2883.95 (64-bit) (Mac)

See https://github.com/andybons/preload/tree/master/static/import for an example of this.

index.html:
<link rel="preload" href="app.js">
<link rel="import" href="import.html">

import.html:
<script src="app.js"></script>

app.js:
console.log('this is the app');

Expected behavior:
app.js is not requested twice. No console warning about it not being used after window.onload.

Actual behavior:
app.js is loaded twice both from Initiator (index):-Infinity. Warning is shown in the console: The resource http://localhost:8080/import/app.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it wasn't preloaded for nothing.
 
Screen Shot 2017-01-04 at 3.56.53 PM.png
75.7 KB View Download

Comment 1 by y...@yoav.ws, Jan 6 2017

Cc: -y...@yoav.ws
Owner: y...@yoav.ws
Status: Assigned (was: Untriaged)
Cc: paulir...@chromium.org
Status: ExternalDependency (was: Assigned)
I think what's happening here is that you forgot to add as="script" to your link rel=preload element(s).

The script tag doesn't see the former link rel preload as something it could use.

+Paul Irish: could we make the warning a bit more useful by hinting at the lack of as="script" as the root cause of the issue?
Components: Blink>Network
Thanks. That fixed it, though I had to remove the crossorigin="anonymous" attribute in my prod app or else it will double-download. Was it being misused? Is this a separate bug?

Comment 5 by y...@yoav.ws, Feb 10 2017

Can you clarify which crossorigin attribute you had to remove? Can you post links to a working example vs. a non-working one?
Currently, on skia-review.googlesource.com, you can check the source of index.html and see the following line:

<link rel="preload" href="https://cdn.googlesource.com/polygerrit_ui/280.0/elements/gr-app.js" crossorigin="anonymous">

When I change this to:

<link rel="preload" href="https://cdn.googlesource.com/polygerrit_ui/280.0/elements/gr-app.js" as="script" crossorigin="anonymous">

It still double downloads, but when I remove the crossorigin attribute:

<link rel="preload" href="https://cdn.googlesource.com/polygerrit_ui/280.0/elements/gr-app.js" as="script">

It works as intended.

Hope this was clear. The example in the first comment also shows this if you follow the same steps.
FWIW: demo link: https://rawgit.com/andybons/preload/master/static/import/index.html

Yoav, can we add text about missing 'as' in the warning?

How about:

>  The resource https://rawgit.com/andybons/preload/master/static/import/app.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.

Comment 8 by addyo@chromium.org, Mar 29 2017

Cc: addyo@chromium.org

Comment 9 by y...@yoav.ws, Jan 1 2018

Status: Started (was: ExternalDependency)
Apologies for dropping the ball on this... Patch at https://chromium-review.googlesource.com/c/chromium/src/+/846980
Project Member

Comment 10 by bugdroid1@chromium.org, Jan 2 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/585988dafb896f900f565db97d7cc48d78e8801c

commit 585988dafb896f900f565db97d7cc48d78e8801c
Author: Yoav Weiss <yoav@yoav.ws>
Date: Tue Jan 02 08:18:53 2018

Clearer warning when preload resource is not used.

There's some confusion when preloaded resources are not used, and the current
warning message is not clear enough. On the issue Paul Irish suggested a better
warning message, that may help reduce the confusion. This CL implemented that
message.

Bug:  678429 
Change-Id: I4d7bda73d243de9d323a007ee336dfd571586d64
Reviewed-on: https://chromium-review.googlesource.com/846980
Reviewed-by: Charlie Harrison <csharrison@chromium.org>
Commit-Queue: Yoav Weiss <yoav@yoav.ws>
Cr-Commit-Position: refs/heads/master@{#526448}
[modify] https://crrev.com/585988dafb896f900f565db97d7cc48d78e8801c/third_party/WebKit/LayoutTests/fast/dom/HTMLLinkElement/link-preload-unused-expected.txt
[modify] https://crrev.com/585988dafb896f900f565db97d7cc48d78e8801c/third_party/WebKit/Source/platform/loader/fetch/ResourceFetcher.cpp

Comment 11 by y...@yoav.ws, Jan 2 2018

Status: Fixed (was: Started)
Sorry guys, understand you guys recently changed the message but it needs another change.
The current message says this:

The resource http://use.typekit.net/some/font/with/some/random/uid/here?withsomeargs=1 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it Please make sure it has an appropriate `as` value and it is preloaded intentionally.

Comment 14 by renc...@gmail.com, May 8 2018

This is because you need to add `crossorigin` to your link tag (or header).
The message could be changed to indicate that sometimes (eg, for fonts) you need to specify `crossorigin` when preloading, otherwise the preload is not useful and the file is loaded twice (once by preload without `crossorigin` set, and one from the page, this time with `crossorigin` set)

Sign in to add a comment