(In reply to Hamish Willee from comment #13)
Thanks Evan, it almost answers my question.
I understand that the header value is a "hint" to the server that this is a preload request. The server can then choose to send back the same resource as for a normal fetch() or something else - e.g. a part of a page. What is sent back will be something that the web page/service worker and the server need to agree.
true is sent in that header, but just the fact you're getting the header at all tells you that it is a preload request, so you could in theory configure one different type of response on getting the header.
But you can change the header value from
true to to
whatever. This means that you can tell the server that you want many different types of responses for each of these.
So my questions are:
- When/why would you want to support multiple formats being sent back? I can see the value in partial page vs whole page, but what's the scenario for partial page vs whole page vs ? that you need to be able to change the header for?
This preload only can be used in ServiceWorker.
In fact, I always assume that ServiceWorkerNavigationPreload always gets partial content from Server.
Since ServiceWorker can save some template content in storages.
But the preload partial content can be different by the conditions.
Considering a page, could be in an iframe, that intercepted by a ServiceWorker can be shown to guest users, login users, premium users.
The page content depends on what kind of account be login in.
ServiceWorker saves some template content for all kinds of users in the cache. And ServiceWorker needs some specific user information saved in the server to synthesize the page.
According to what kind of account be login in, the header can be set with different data to get different information for page synthesizing.
This might not be a good case since it could be achieved through cookies. However, sometimes using cookies might not be a good option.
- If you do need to do this, when do you do it? Say you want to configure which header is sent for different files in different folders - by the time the service worker gets loaded so you might change the header value the resource will already have preloaded - right? So I'm confused about when it would make sense to have more than just
About when to set up the header value, I think I have no answer for it. It depends on what the page would provide.
But for the mentioned case, the header value could be set while the login/logout/session expired by ServiceWorkerRegistration.NavigationPreloadManager.setHeaderValue().
Sorry if this is a dumb question!