You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Don't think the "type" attribute is quite fit for purpose #6
As far as I can tell, "type" is being used for prioritisation and appropriate request headers (eg, Accept header for images), but elsewhere in the platform the origin of the request is used for this, not the type.
By "origin" do you mean type of attribute (like img vs script, etc)? We don't have that context here, and I don't see how we can leverage the request context when all we have is a bunch of hints in the document head?
The problem I'm trying to address is what we ran into with current rel=subresource implementation in Chrome: effectively its preload but without content-type information and because of that all requests are of the same (low) priority and end up hurting some pages (e.g. subresource load is initiated at a lower priority than the actual resource would get if it was discovered by the doc parser).
Practically speaking, all browsers implement content-type prioritization logic already: the parser sets relative priority based on context (img, stylesheet, js, etc), so I'm just trying to leverage what we already have in place.
One concern I have with using type for prioritization is that there may be cases where it's not granular enough.
E.g. a recent tweet by @scottjehl, where he asks about "non-critical CSS".
So, we may want a way for the author to communicate priorities beyond type. I don't know what the best way for that though.
@yoavweiss well, if its not critical, then I'd argue it shouldn't be in the preload list? The point of preload is to help accelerate the initial load when all you have is a few KB of HTML markup (after first RTT) and/or (likely) blocking JS. The non-critical stuff will be discovered and downloaded later.
By "origin" do you mean type of attribute (like img vs script, etc)?
Ah, sorry, origin was the wrong word to use. I mean the thing that initiated the request. We call it context in serviceworker.
We don't have that context here, and I don't see how we can leverage the request context when all we have is a bunch of hints in the document head?
You're using type for that at the moment, and I'm saying that's not the best thing to use.
The problem I'm trying to address is what we ran into with current rel=subresource implementation in Chrome: effectively its preload but without content-type information and because of that all requests are of the same (low) priority and end up hurting some pages (e.g. subresource load is initiated at a lower priority than the actual resource would get if it was discovered by the doc parser).
Practically speaking, all browsers implement content-type prioritization logic already: the parser sets relative priority based on context (img, stylesheet, js, etc), so I'm just trying to leverage what we already have in place.
Yes, the priority is set on context, not content-type. Eg, <script src="whatever"> will have a higher priority than an XHR request to the same url, even though the return will have the same content type. It'd be better to do:
Not only will this better handle prioritisation, it'll request with the "image" with image/webp in the Accept header, because it knows this is an image context. It'll request the 2nd as it does XHR, using no credentials if the URL is cross-origin.
It's about ensuring that you get a cache hit when the actual request is made.
I'm not sure I understand. I know that @igrigorik is writing the type attribute thinking primarily about prioritization. And @jakearchibald seems to emphasize that this is about making sure you get a cache hit (which, as I've said in issue #5, is an implementation issue of which the specification should be agnostic. To be clear, I'm referring to the 'cache' part of it, not the actual request matching / "hit" part of it).
Are we primarily discussing the name of the attribute so we can have consistency? type vs context?
AFAICT, @igrigorik is misunderstanding @jakearchibald's point. Jake is primarily focused on making sure that we emit the correct headers so that the request matches. The context is important for this, since we'll emit different request headers (e.g. Accept) depending on the context. But this context in most cases is just the content type. In XHR, there is no context, and the content type only gets assigned in the very end when you take this opaque blob of data and insert into the DOM with a specific element type.
@igrigorik seems to infer more than what @jakearchibald is saying. That said, providing manual controls over the magic heuristic prioritization value that the UA calculates is indeed something that we've discussed (I with @slightlyoff and separately with @jakearchibald). It's definitely possible for us to let the UA parse the element and heuristically assign a priority value to it, but let that priority value be manually overridden by the developer via an attribute. This formalizes the UA's heuristic prioritization. Developers desperately need something like this, but it limits what the UA might want to do long-term, which is why I've been very hesitant about it. What if we want multiple dimensions of priority? For example, an idle priority. And if the UA's heuristic treats XHR as priority X today, but later on, we want to set it to X-1 or X+1 or whatever, we may be limited in doing so because of all the existing web content.
This is all complicated and therefore I haven't written it up since I'm still working out the details in my head. I'm fairly nervous about committing to any fine grained prioritization scheme since it's an area that people don't fully understand yet, and the implications of which are fairly large.
I think the discussion about exposing fine grained prioritization control (beyond content type) should happen at some point, but it does not and should not block Resource Hints.
@willchan to be honest, I'm not sure if I'm assuming more or less of what Jake is saying, but here's what I want to say... :)
Today browsers already implement prioritization logic based on context (image, script, etc), and given that context is also exposed in request object in ServiceWorker, chances are it will be used to impact routing, caching, etc. Putting the two together, it makes sense to ensure that correct context is set on hint-initiated requests when they reach SW, and (it seems to me that) the simplest way to do that is by providing an explicit context attribute as Jake suggested. Of course, we could use "type" instead and then map the type to a context, but that seems like an unnecessary layer of indirection?
Jake is primarily focused on making sure that we emit the correct headers so that the request matches. The context is important for this, since we'll emit different request headers (e.g. Accept) depending on the context. But this context in most cases is just the content type.
In most cases, yeah, but with whatever.svg the type is image/svg+xml, whereas context can be more expressive, it could be image, xmlhttprequest, frame.
In XHR, there is no context, and the content type only gets assigned in the very end when you take this opaque blob of data and insert into the DOM with a specific element type.
We have a xmlhttprequest context (I called it connect earlier, but I was confusing it with the CSP name).
Also, question.. What's the right context for a navigation? Could be a due to a click on a link, window.location, etc. I'm using generic "fetch" in the spec, but.. not sure that's the best one?
@annevk@jakearchibald wait, I think there is a conflict here.. Current context list contains prefetch and subresource (but skips prerender, which is odd?) all of which map to their <link rel=...> equivalents. This, by itself, makes sense, but that's not what I'm after here...
The problem is that we need to indicate the type/priority of the resource communicated via the hint, such that the UA can set the appropriate priority on the request. This is why I originally went with type instead of context.
a) There is an argument that it makes sense to have both the context and type.. In which case, I'd have to unwind the change here and go back to type="{mime}".
b) Alternatively, drop subresource and prefetch and instead say that the context should be set to the value in which that resource will be used later? I.e. if the prefetch is for an image asset, then context should be set to image, and so on?
Right. Maybe the LINK attribute can be "contexts" and it can support a list of allowed contexts for this resource? Feels ugly I know but it would allow us to avoid having to make a third resource typing scheme in addition to type and context.
@annevk what about internal? Perhaps a bit of a stretch, but at high level I think triggering a swap of prerendered page maps pretty well into "other user agent usage" / forward navigation?
@bizzbyster Resource::Type is Fetch's resource context, so I don't think that helps.
@willchan what I'm saying is that resource context is more granular as it has several consumers. So you can't say navigate, you would list hyperlink or form.
Maybe we should have a distinction between contextSource and contextDestination. I'm somewhat curious how this works in the source code today. Feedback from @mikewest and maybe @bzbarsky would help.
One thing we might want to enable developers to do is to provide higher priority hints for objects needed before start of render, followed by hints for objects needed for visual completeness, etc. Additionally, developers might want to prioritize "serializer" objects that block further fetches. The context and type paradigm don't seem to lend themselves to specifying this notion of a prefetch graph. Any ideas?
If we go in that direction, paging @Hixie as he is trying to figure out how to reconcile the various (JavaScript modules, HTML imports, other HTML features) dependency management systems.
Maybe we should have a distinction between contextSource and contextDestination. I'm somewhat curious how this works in the source code today. Feedback from @mikewest and maybe @bzbarsky would help.
@annevk how would Source vs Destination distinction help us in this case?
As I noted in the whatwg thread, I'm wondering if we can instead separate download from processing. As in, the context is applied when the fetched asset is "matched" with a request.
I'm not sure. I know that for CSP we need the form annotation. And we need the context frame type (as defined in Fetch). What you want seems like a more generic annotation. I have no idea how we would reconcile the need for both form and navigate without two distinct types.
@annevk perhaps there is a distinction to be made based on type of request? Hint requests should be idempotent (i.e. GET) and should not trigger state changes on the server. Whereas form submit is a POST and it would make sense that you'd want to run some policy checks before the request is sent.
@annevk thinking about this some more, I'm coming around to the contextDestination idea. Specifically, contextSource can be set as {preload, prerender}, but contextDestination is an optional parameter on the hint that indicates the likely target context -- this has nothing to do with CSP and everything with setting reasonable defaults for fetch priority, headers, etc. Later, the hinted response is consumed by a script, img, etc, and the CSP policies are applied at that time -- this is exactly how rel=subresource and rel=prefetch work today.
In the first case I'm using context attribute to indicate the likely destination context, such that the UA can infer the content type, set the right headers, priorities, etc. In the second case, I'm prerendering a page, the navigation to which may be triggered through different destination contexts: clicking on a link, window.location, etc. Hence "unknown" and the UA just uses some reasonable defaults. Finally, in the last case, I'm prerendering a script, and I can once again communicate that to let the UA set the right fetch settings.
This approach has the benefit of preserving the source context, and the "context" attribute becomes an optional hint to help the UA determine the likely destination context.
<!-- set default headers, priority based on (likely) destinationContext, but then customize if needed --><linkrel="preload" href="/some/image.jpg" params="{destinationContext: 'image', priority: {...}}" />
In fact, assuming something like above is reasonable, it seems like a better and more flexible solution.
The tentative plan is that at least Accept & Accept-Language are set at the API-layer, e.g. by the implementation of <img>, so that they get exposed to service workers. I guess for this that would mean that the implementation of params has some kind of lookup table to set those headers as a convenience.
@annevk it seems like destinationContext would be initializing defaults at the API layer, but those defaults can be overridden by a custom header. For example:
In the above case destinationContext would initialize the default set of headers for an image fetch (as if the download was initiated via img), but the custom header in the same options hash can then override the default Accept value. Any protected headers (Host, etc) would be ignored by the UA.
Activity
igrigorik commentedon Jul 10, 2014
By "origin" do you mean type of attribute (like img vs script, etc)? We don't have that context here, and I don't see how we can leverage the request context when all we have is a bunch of hints in the document head?
The problem I'm trying to address is what we ran into with current
rel=subresourceimplementation in Chrome: effectively itspreloadbut without content-type information and because of that all requests are of the same (low) priority and end up hurting some pages (e.g. subresource load is initiated at a lower priority than the actual resource would get if it was discovered by the doc parser).Practically speaking, all browsers implement content-type prioritization logic already: the parser sets relative priority based on context (img, stylesheet, js, etc), so I'm just trying to leverage what we already have in place.
yoavweiss commentedon Jul 10, 2014
One concern I have with using
typefor prioritization is that there may be cases where it's not granular enough.E.g. a recent tweet by @scottjehl, where he asks about "non-critical CSS".
So, we may want a way for the author to communicate priorities beyond
type. I don't know what the best way for that though.igrigorik commentedon Jul 10, 2014
@yoavweiss well, if its not critical, then I'd argue it shouldn't be in the preload list? The point of preload is to help accelerate the initial load when all you have is a few KB of HTML markup (after first RTT) and/or (likely) blocking JS. The non-critical stuff will be discovered and downloaded later.
jakearchibald commentedon Jul 10, 2014
Ah, sorry, origin was the wrong word to use. I mean the thing that initiated the request. We call it context in serviceworker.
You're using
typefor that at the moment, and I'm saying that's not the best thing to use.Yes, the priority is set on context, not content-type. Eg,
<script src="whatever">will have a higher priority than an XHR request to the same url, even though the return will have the same content type. It'd be better to do:Not only will this better handle prioritisation, it'll request with the "image" with
image/webpin theAcceptheader, because it knows this is an image context. It'll request the 2nd as it does XHR, using no credentials if the URL is cross-origin.It's about ensuring that you get a cache hit when the actual request is made.
igrigorik commentedon Jul 10, 2014
Ah, interesting, I like it! So, to confirm that I understand this correctly:
contextattribute on<link>where we can manually set itCorrect? Also, as an aside, is there a definition for each of the enum values? What's
connect? I'm assumingcrossoriginis a whole other discussion.../cc @willchan relevant to our earlier prioritization discussion... Or, at least, a step in a right direction.
willchan commentedon Jul 10, 2014
I'm not sure I understand. I know that @igrigorik is writing the type attribute thinking primarily about prioritization. And @jakearchibald seems to emphasize that this is about making sure you get a cache hit (which, as I've said in issue #5, is an implementation issue of which the specification should be agnostic. To be clear, I'm referring to the 'cache' part of it, not the actual request matching / "hit" part of it).
Are we primarily discussing the name of the attribute so we can have consistency?
typevscontext?AFAICT, @igrigorik is misunderstanding @jakearchibald's point. Jake is primarily focused on making sure that we emit the correct headers so that the request matches. The context is important for this, since we'll emit different request headers (e.g. Accept) depending on the context. But this context in most cases is just the content type. In XHR, there is no context, and the content type only gets assigned in the very end when you take this opaque blob of data and insert into the DOM with a specific element type.
@igrigorik seems to infer more than what @jakearchibald is saying. That said, providing manual controls over the magic heuristic prioritization value that the UA calculates is indeed something that we've discussed (I with @slightlyoff and separately with @jakearchibald). It's definitely possible for us to let the UA parse the element and heuristically assign a priority value to it, but let that priority value be manually overridden by the developer via an attribute. This formalizes the UA's heuristic prioritization. Developers desperately need something like this, but it limits what the UA might want to do long-term, which is why I've been very hesitant about it. What if we want multiple dimensions of priority? For example, an idle priority. And if the UA's heuristic treats XHR as priority X today, but later on, we want to set it to X-1 or X+1 or whatever, we may be limited in doing so because of all the existing web content.
This is all complicated and therefore I haven't written it up since I'm still working out the details in my head. I'm fairly nervous about committing to any fine grained prioritization scheme since it's an area that people don't fully understand yet, and the implications of which are fairly large.
igrigorik commentedon Jul 11, 2014
I think the discussion about exposing fine grained prioritization control (beyond content type) should happen at some point, but it does not and should not block Resource Hints.
@willchan to be honest, I'm not sure if I'm assuming more or less of what Jake is saying, but here's what I want to say... :)
Today browsers already implement prioritization logic based on context (image, script, etc), and given that
contextis also exposed in request object in ServiceWorker, chances are it will be used to impact routing, caching, etc. Putting the two together, it makes sense to ensure that correctcontextis set on hint-initiated requests when they reach SW, and (it seems to me that) the simplest way to do that is by providing an explicitcontextattribute as Jake suggested. Of course, we could use "type" instead and then map the type to a context, but that seems like an unnecessary layer of indirection?willchan commentedon Jul 11, 2014
Got it. That seems reasonable.
jakearchibald commentedon Jul 11, 2014
@igrigorik
Yeah. In ServiceWorker you get
.contextas part of the fetch event (or request object, we haven't decided yet). The enums are at http://fetch.spec.whatwg.org/#concept-request-context. I'm hoping we'll be able to use these context types to set sensible defaults onRequestobjects too w3c/ServiceWorker#318 (comment).Thankfully that attribute already exists on
<link>for this purpose http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#the-link-element@willchan
In most cases, yeah, but with
whatever.svgthe type isimage/svg+xml, whereascontextcan be more expressive, it could beimage,xmlhttprequest,frame.We have a
xmlhttprequestcontext (I called itconnectearlier, but I was confusing it with the CSP name).igrigorik commentedon Jul 25, 2014
@jakearchibald how does that look?
Also, question.. What's the right context for a navigation? Could be a due to a click on a link, window.location, etc. I'm using generic "fetch" in the spec, but.. not sure that's the best one?
annevk commentedon Jul 28, 2014
Navigation depends.
window.location,<a>, ... have their own contexts. For those triggered directly by the user we do not have one yet. See https://www.w3.org/Bugs/Public/show_bug.cgi?id=26247#c15 We'll add one soonish I suspect.igrigorik commentedon Jul 28, 2014
@annevk @jakearchibald wait, I think there is a conflict here.. Current
contextlist containsprefetchandsubresource(but skipsprerender, which is odd?) all of which map to their<link rel=...>equivalents. This, by itself, makes sense, but that's not what I'm after here...The problem is that we need to indicate the type/priority of the resource communicated via the hint, such that the UA can set the appropriate priority on the request. This is why I originally went with
typeinstead ofcontext.a) There is an argument that it makes sense to have both the context and type.. In which case, I'd have to unwind the change here and go back to type="{mime}".
b) Alternatively, drop
subresourceandprefetchand instead say that the context should be set to the value in which that resource will be used later? I.e. if the prefetch is for an image asset, then context should be set toimage, and so on?Thoughts?
[1] http://fetch.spec.whatwg.org/#concept-request-context
annevk commentedon Jul 29, 2014
Not sure anyone proposed
prerender.How can you tell what
prefetchwill be used for?9 remaining items
bizzbyster commentedon Jul 30, 2014
Right. Maybe the LINK attribute can be "contexts" and it can support a list of allowed contexts for this resource? Feels ugly I know but it would allow us to avoid having to make a third resource typing scheme in addition to type and context.
igrigorik commentedon Jul 30, 2014
@annevk what about
internal? Perhaps a bit of a stretch, but at high level I think triggering a swap of prerendered page maps pretty well into "other user agent usage" / forward navigation?whatwg/fetch@2cc41cf#diff-1feda49b40370635faef8b655f144f64R595
annevk commentedon Jul 31, 2014
@bizzbyster Resource::Type is Fetch's resource context, so I don't think that helps.
@willchan what I'm saying is that resource context is more granular as it has several consumers. So you can't say
navigate, you would listhyperlinkorform.Maybe we should have a distinction between contextSource and contextDestination. I'm somewhat curious how this works in the source code today. Feedback from @mikewest and maybe @bzbarsky would help.
DavidLerner commentedon Aug 7, 2014
One thing we might want to enable developers to do is to provide higher priority hints for objects needed before start of render, followed by hints for objects needed for visual completeness, etc. Additionally, developers might want to prioritize "serializer" objects that block further fetches. The context and type paradigm don't seem to lend themselves to specifying this notion of a prefetch graph. Any ideas?
annevk commentedon Aug 7, 2014
If we go in that direction, paging @Hixie as he is trying to figure out how to reconcile the various (JavaScript modules, HTML imports, other HTML features) dependency management systems.
igrigorik commentedon Aug 7, 2014
Kicked off a thread on whatwg: http://lists.w3.org/Archives/Public/public-whatwg-archive/2014Aug/0027.html
igrigorik commentedon Aug 14, 2014
@annevk how would Source vs Destination distinction help us in this case?
As I noted in the whatwg thread, I'm wondering if we can instead separate download from processing. As in, the context is applied when the fetched asset is "matched" with a request.
annevk commentedon Aug 15, 2014
I'm not sure. I know that for CSP we need the
formannotation. And we need the context frame type (as defined in Fetch). What you want seems like a more generic annotation. I have no idea how we would reconcile the need for bothformandnavigatewithout two distinct types.annevk commentedon Aug 15, 2014
Oh, and context we most definitely need when fetching as CSP wants to block that, the transmission of bytes.
igrigorik commentedon Aug 15, 2014
@annevk perhaps there is a distinction to be made based on type of request? Hint requests should be idempotent (i.e. GET) and should not trigger state changes on the server. Whereas
formsubmit is a POST and it would make sense that you'd want to run some policy checks before the request is sent.igrigorik commentedon Aug 16, 2014
@annevk thinking about this some more, I'm coming around to the
contextDestinationidea. Specifically,contextSourcecan be set as {preload, prerender}, butcontextDestinationis an optional parameter on the hint that indicates the likely target context -- this has nothing to do with CSP and everything with setting reasonable defaults for fetch priority, headers, etc. Later, the hinted response is consumed by a script, img, etc, and the CSP policies are applied at that time -- this is exactly how rel=subresource and rel=prefetch work today.A couple of concrete examples:
In the first case I'm using
contextattribute to indicate the likely destination context, such that the UA can infer the content type, set the right headers, priorities, etc. In the second case, I'm prerendering a page, the navigation to which may be triggered through different destination contexts: clicking on a link, window.location, etc. Hence "unknown" and the UA just uses some reasonable defaults. Finally, in the last case, I'm prerendering a script, and I can once again communicate that to let the UA set the right fetch settings.This approach has the benefit of preserving the source context, and the "context" attribute becomes an optional hint to help the UA determine the likely destination context.
Alternatively, we just push this "context" business into fetch params. Perhaps with something like this: http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2014-August/297437.html
In fact, assuming something like above is reasonable, it seems like a better and more flexible solution.
annevk commentedon Aug 16, 2014
Inserting headers based on the destinationContext seems okay, but needs to be elaborated in detail. Is that
Accept,Accept-Language? Where would you expect those to be set per http://fetch.spec.whatwg.org/#http-header-layer-division as it will become observable soon?The tentative plan is that at least
Accept&Accept-Languageare set at the API-layer, e.g. by the implementation of<img>, so that they get exposed to service workers. I guess for this that would mean that the implementation ofparamshas some kind of lookup table to set those headers as a convenience.igrigorik commentedon Aug 21, 2014
@annevk it seems like destinationContext would be initializing defaults at the API layer, but those defaults can be overridden by a custom header. For example:
In the above case
destinationContextwould initialize the default set of headers for an image fetch (as if the download was initiated viaimg), but the custom header in the same options hash can then override the default Accept value. Any protected headers (Host, etc) would be ignored by the UA.Does that seem reasonable?
igrigorik commentedon Aug 22, 2014
Updated the spec to use
fetch-settingsin 955a9ff. See here:https://igrigorik.github.io/resource-hints/#fetch-settings
@annevk please take a look, let me know if that makes sense.
I'm closing this bug, let's continue the discussion in: #21