-
Notifications
You must be signed in to change notification settings - Fork 352
Initializing context/content specific fetch defaults #43
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
Comments
To be clear, The problematic case with allowing About initializing defaults. We could do this in fetch, but are engines actually setting these defaults based on an enum in the network layer or are they set in the DOM layer based on the environment? I can see how we could take over handling (As for header management. The way it works is that feature-specific headers are set by those invoking fetch. So currently e.g. the specification for |
That makes sense. In the case of
Our goal here is to provide context to the engine where its currently missing, such that the engine can make more informed decisions. For example, when the engine sees an By contrast, if you try to In short, I think "as" is sufficient as a bootstrapping mechanism to help the UA set some defaults, it doesn't need to provide the exact same behavior. |
You have to get more specific than "engine" and "some defaults". We actually have to define that in more detail than just a hint since it is all rather observable and user agents will be required to support the same functionality. |
Sure, let's make it concrete. The developer provides the destination context via "as" attribute, e.g.. fetch('/gallery/photo.jpg', {as: 'image'}).then(...) or <link rel=preload href=/gallery/photo.jpg as=image> The user agent needs to...
I know that in Blink we advertise different headers, and assign different priorities, based on type of resource being fetched. AFAIK, same applies to FF, WebKit, and IE. @pmeenan @mcmanus @toddreifsteck any thoughts or comments on this one? |
What I'd like to do is that if we're certain that e.g. And then go through that for each desired feature so that it's clear what the realm of a request context (e.g. "image") is and what's in the realm of a feature (e.g. In the case of |
So Re: "useful for SW only". There is no
(The other reason why I think we want it for a |
An alternative approach would be to reuse the media element |
Yes: https://www.w3.org/Bugs/Public/show_bug.cgi?id=23502 (marked as "Needs Impl Interest") |
Having If we go that route then maybe, for the case of |
I don't understand why you think you would not be able to control the priority. That's a largely orthogonal feature we have not sorted out yet. |
I agree that it's orthogonal to context, but the original intention of |
If the intent was fetch priority, |
@annevk I'll defer to you on @yoavweiss I agree with @annevk I think changing priorities is an orthogonal discussion. "as" is used to initialize request defaults, other options provided by the developer would override them. For example...
Changing prioritization would work the same way, we "just" need to define syntax to control transport priorities and dependencies... previous discussion on whatwg. Assuming we arrive at some such thing, it could potentially look as... commence handwaving...
Or some such. On a more tactical level, I'm wondering if we can unblock Resource Hints / Preload and continue iterating on other details in parallel... Concretely:
The response blob vs. URL does not block either RH or Preload because both are used to populate the cache, and are then consumed by another element/object that would enforce its CSP policy. @annevk wdyt, does that sound reasonable? I'd love to land the RH and Preload refactors, as they're blocking implementation in Blink. |
I think for Resource Hints / Preload |
Actually, strike that. In the presence of service workers, preload et al, would cease to work since you cannot set context for |
@annevk not sure I followed that, can you elaborate a bit more? Why would SW break preload? As far as nomenclature goes, I'm open to ideas and suggestions. That said, I'll just note that at least one (good, I think) argument for |
@igrigorik SW only has access to
Anyway, |
@annevk thanks, that makes sense. Anything I can do to help land this in Fetch? At a minimum, I just need some hooks to map the attribute value to fetch initialization, or some such. Both RH and Preload are currently blocked on this - e.g. w3c/preload#17 (comment). |
If you could help prepare the list of header names/values against contexts that would help. I can do the necessary refactoring. (Basically #concept-fetch needs some kind of preprocessor that sets these headers before invoking #concept-fetch.) |
@annevk after doing a quick spot-check, the advertised Accept headers are all over the map... Chrome...
Firefox
Safari
IE
I guess one way to look at this would be to say that perhaps Fetch is the one place where we can (finally) rationalize and normalize all this across the different browsers? However, even if we were to go down that route, we still need to allow for UA-specific values (e.g. WebP advertisements for Chrome, and so on). As a result, perhaps a fixed list of /cc @mnot |
It'd be nice, but I suspect implementations are going to want to do their own thing here, to a degree. Fetch could give advice about what's appropriate; e.g., sending image/wepb for a HTML fetch doesn't make sense (I get that they're trying to hint to the server that it's OK to send links to webp images in the HTML, but that's not really what accept is for, and other browsers don't do it). We could also save a few bytes by recommending that they not send /; it doesn't do anything (especially when it's on its own)`. Latest and greatest: |
The problems are: inline images; direct image requests (when we don't have the
Been tried, sadly omitting the Accept header breaks bunch of sites. I'll see if I can dig up the old thread around this. P.S. That said.. some consistency would be nice. It would help weed out things like crbug.com/443094 |
I think Fetch could have a "SHOULD" value for |
…n context. See #43 This also allowed for some nice cleanup as now internal parameters are no longer exposed at the base of the algorithm. I also made the note about response tainting visible as it might just as easily confuse readers.
As part of this, introduce various context groupings to avoid duplicating lists throughout the specification.
I have added header initialization for |
@annevk nice. A couple of questions...
|
Well, it already says "should" so user agents have some leeway and I think user agents ought to converge on supported types long term. I'd rather not mention formats that don't have buy in from everyone. We can mention priorities I suppose. Pointer? Part of the problem with priorities is that I know that e.g. in Gecko we want to do more. We want to not only take into account the context, but also layout information and such. So setting priority in Fetch may be too late. |
Fair enough 👍
I don't think it's any different from Accept, which may also be set upstream - e.g. through explicit Accept header passed to fetch(). For priority, we could use similar logic: "if requests transport priority is not set, use the request's context to initialize the transport priority", or some such. Perhaps we can just add this as a substep in fetching algorithm - say, between current steps 2-3? |
That seems reasonable. What reference should I use for priorities? |
The best definition is "stream (request) priority" section in HTTP/2: https://tools.ietf.org/html/draft-ietf-httpbis-http2-17#section-5.3. For HTTP/1.x the priority is not communicated to the server, but is used internally by the net-stack to prioritize order and request dispatch times. Perhaps... ~"if requests transport priority is not set, use the request's context to initialize the request priority - e.g. stream weight and dependency for HTTP/2, or equivalent priority class used to prioritize dispatch and processing of HTTP/1.x requests." |
I guess I should also give request a priority field then whose value and function is mostly left as an exercise to the reader. |
Yep, sounds good. As a side note, there was this: http://lists.w3.org/Archives/Public/public-whatwg-archive/2014Aug/0081.html .. except, we never reached any meaningful conclusions on that thread. That said, now that the dust has settled on HTTP/2, I think we can take another run at it. In the meantime, exposing a "priority" field on fetch is sufficient. We can refine how that looks later. |
When initiating a fetch request for a resource, the user agent initializes the fetch with content/context specific settings. For example, when fetching an
<img>
, the UA applies the appropriateimage-src
CSP checks; may advertise different set of request headers (e.g. advertise support for some image formats viaAccept
header, and may emit additional "hint" headers); may set different transport options, such as request priority, dependencies, etc.How do we enable the same functionality with
fetch()
API? Without the above, in the worst case, an image resource fetch initiated viafetch()
may violate CSP, will return an incorrect/suboptimal asset due to missing headers, and may be fetched with incorrect priority. Of course, images are just one example; same logic applies to all other content types. Related discussions:Intuitively, the difference between using
fetch()
vs. say, and<img>
, is that the latter knows its context and is thus able to initialize all the right checks + properties. Perhaps we can address this whole issue by providing "treat this fetch as if it was an 'image'" setting or signal? Handwaving...fetch(url, {as: 'image', headers: {...}, otherOpt: {}, ...})
as
(or whatever fits best) as an explicit context signal that initializes appropriate defaults?headers
and other fetch options are then applied on top of initialized defaults as overridesThe mental model here is very similar to what @domenic proposed in #37 (comment):
Assuming above sounds plausible, we could then also enable this in other parts of the platform:
<img src="photo.jpg" fetch-settings="{...}"
> -- implicit:as == image
, andfetch-settings
can be used to override other UA + fetch defaults.<link rel=preload as="image" href="photo.jpg" fetch-settings="{...}">
--as
is declared explicitly, and options passed in through same mechanism.WDYT, does it sound crazy?
The text was updated successfully, but these errors were encountered: