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

Specifying or using preload twice #85

Closed

Description

@yutakahirano

Hi, I have several questions regarding reusing preloads.

<link rel="preload" href="/resource">

<script>
let p1 = fetch("/resource");
let p2 = fetch("/resource");
</script>

Assume "/resource" is served with "cache-control: no-store" header.

  1. Should / can we use the response fetched by the link element to the first fetch() call? (I believe yes. Although "no-store" is specified, the preloaded resource has not been used, so using it is fine.)
  2. Should / can we use the response fetched by the link element to the second fetch() call? (I believe no. As the resource is used by the first fetch call, reusing it violates the HTTP cache semantics.)

If my guesses for the questions are correct, what is the preferred way to preload twice? Is the following code fine?

<link rel="preload" href="/resource">
<link rel="preload" href="/resource">

<script>
let p1 = fetch("/resource");
let p2 = fetch("/resource");
</script>

cc: @yoavweiss, @annevk, @hiroshige-g

Activity

  1. yoavweiss commented on Feb 8, 2017

    @yoavweiss
    Contributor

    My intuition regarding those questions matches yours. I'm not sure if/how the "preload twice" scenario would work, nor do I think it's a major use-case.

    In general, I'm not aware of resource reuse rules being specified for preload or for other resource fetches.
    e.g.

    <img src=foo>
    <script src=foo></script>
    

    is likely to result in two resource fetches (which may or may not be coalesced at the network layer), but I'm not aware of this being defined anywhere. I think we should define those rules and document the current state. The Fetch spec is probably where these definitions should be.

  2. annevk commented on Feb 8, 2017

    @annevk
    Member

    As far as I know nothing allows for deduplication at the moment.

  3. igrigorik commented on Feb 11, 2017

    @igrigorik
    Member

    If you preload a no-store image and then load it twice via two img elements.. I believe, at least in Chrome, we'll end up reusing the same response in both cases -- right? Why would fetch() be different, instead of using an image element?

  4. annevk commented on Feb 12, 2017

    @annevk
    Member

    If someone could actually define preloading (and write tests) we'd no longer need to have these conversations.

  5. yoavweiss commented on Feb 12, 2017

    @yoavweiss
    Contributor

    I agree this needs specifying, but this is not specific to link preload.

    e.g. <img src=foo><img src=foo> will reuse the same response, while 2 fetch("foo") calls will not, regardless of preload.

  6. annevk commented on Feb 12, 2017

    @annevk
    Member

    That is specified actually. That's because HTML has image URL deduplication. (I forgot about that above, because it happens above the Fetch layer.)

  7. yoavweiss commented on Feb 12, 2017

    @yoavweiss
    Contributor

    True, but the same is true for <script src=foo><script src=foo> which isn't deduped in HTML AFAIK.

  8. yutakahirano commented on Feb 13, 2017

    @yutakahirano
    ContributorAuthor

    I think basically keeping HTTP cache semantics is good though I know the cache in Blink (blink::MemoryCache) in not conformant.

    Regarding fetch() / XHR, They're JS APIs and developers tend to want more consistent behavior for them than for img / css / etc, I think. I once got a request for XHR (https://crbug.com/333804) and the cache in Blink is now basically disabled for fetch() / XHR.

  9. yutakahirano commented on Feb 13, 2017

    @yutakahirano
    ContributorAuthor

    That is specified actually. That's because HTML has image URL deduplication. (I forgot about that above, because it happens above the Fetch layer.)

    Sorry for my ignorance, can you give me a link? I'm interested in how it's defined.

  10. annevk commented on Feb 13, 2017

    @annevk
    Member
  11. yoavweiss commented on Feb 13, 2017

    @yoavweiss
    Contributor

    @annevk I disagree it's an issue in Blink, but it seems there's divergence here. http://jsbin.com/bovagohehu/edit?html,console,output outputs a single download for Chrome, and 2 for Firefox. AFAIK, Safari would also issue a single download here (but hard to test, as ResourceTiming is not yet exposed).

  12. annevk commented on Feb 13, 2017

    @annevk
    Member

    It's an issue in Blink because it violates the standard. If you want that kind of behavior you'd need to work on standardizing it.

  13. yoavweiss commented on Feb 13, 2017

    @yoavweiss
    Contributor

    I don't disagree about the need for standardization, but not sure this behavior didn't precede current spec (this was the behavior in WebKit when I first started digging around that code in 2012)

  14. yutakahirano commented on Feb 13, 2017

    @yutakahirano
    ContributorAuthor

    @annevk Thank you.

  15. yoavweiss commented on May 31, 2017

    @yoavweiss
    Contributor

    This needs specifying as part of #97

  16. igrigorik commented on Jul 21, 2017

    @igrigorik
    Member

    Added a note in #97 to address this.. let's continue discussion there to consolidate threads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions