Closed Bug 1750515 Opened 4 months ago Closed 3 months ago

Enable NavigationPreload on Nightly

Categories

(Core :: DOM: Service Workers, task, P2)

task

Tracking

()

RESOLVED FIXED
99 Branch
Tracking Status
firefox99 --- fixed

People

(Reporter: edenchuang, Assigned: edenchuang)

References

Details

(Keywords: dev-doc-complete)

Attachments

(1 file)

NavigationPreload API currently is disable by prefs dom.serviceWorker.navgationPreload.enabled.
This bug makes NavigationPreload be enabled on Nightly.

Assignee: nobody → echuang
Severity: -- → S3
Priority: -- → P2
Pushed by echuang@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/57b7b4ac1ef3
Enable NavigationPreload API on Nightly. r=dom-worker-reviewers,smaug
Depends on: 1753025
Flags: needinfo?(echuang)
Pushed by echuang@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/c07607b89a61
Enable NavigationPreload API on Nightly. r=dom-worker-reviewers,smaug
Flags: needinfo?(echuang)
Pushed by echuang@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/9771e7cbe148
Enable NavigationPreload API on Nightly. r=dom-worker-reviewers,smaug

Backed out 3 changesets (Bug 1750515, Bug 1753025) for causing wpt failures on idlharness.https.any.<...>.
Backout link
Push with failures
Failure Log

Flags: needinfo?(echuang)
Flags: needinfo?(echuang)
Pushed by echuang@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/33e221758c25
Enable NavigationPreload API on Nightly. r=dom-worker-reviewers,smaug
Status: NEW → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 99 Branch
Regressions: 1754786
Regressions: 1755416
Keywords: dev-doc-needed

FF99 docs work for this can be tracked in https://github.com/mdn/content/issues/13367#issuecomment-1061265650

The Service-Worker-Navigation-Preload HTTP header is sent with the preloading resource request, with a value of true by default, which can be set to any value with setHeader().
The value may be used by a server to configure its response in a different way than the normal fetch response. In https://developers.google.com/web/updates/2017/02/navigation-preload there is an example that suggests a special value might be set to tell the server that you want to just be sent back part of the file, or a JSON representation rather than the original, or whatever.

When would you need to set multiple different behaviors on preload? Is this so a server can somehow have requests for the resource from different managers and send them different resources?

Flags: needinfo?(echuang)

Hello Hamish

(In reply to Hamish Willee from comment #11)

FF99 docs work for this can be tracked in https://github.com/mdn/content/issues/13367#issuecomment-1061265650

Thank you for document this.

The Service-Worker-Navigation-Preload HTTP header is sent with the preloading resource request, with a value of true by default, which can be set to any value with setHeader().
The value may be used by a server to configure its response in a different way than the normal fetch response. In https://developers.google.com/web/updates/2017/02/navigation-preload there is an example that suggests a special value might be set to tell the server that you want to just be sent back part of the file, or a JSON representation rather than the original, or whatever.

When would you need to set multiple different behaviors on preload? Is this so a server can somehow have requests for the resource from different managers and send them different resources?

In fact, we don't know how the header value will be used by the server.
ServiceWorkerNavigationPreload is a feature that speeds up the response time of ServiceWorker.
Launching a ServiceWorker could be a time-consuming task. The idea of ServiceWorkerNavigationPreload is to fetch the navigation resource through the network when launching the ServiceWorker. The fetch response would be sent to the ServiceWorker by FetchEvent.preloadResponse.
Once ServiceWorker is ready, it can directly call FetchEvent.respondWith() the preload response. Such that the ServiceWorker doesn't need call fetch () in its FetchEvent handler.
Of course, in some cases, the preloaded response can be handled/combined/modified/synthesized by ServiceWorker's FetchEvent handler. It means ServiceWorker might just need some small and meaningful data from the network. In this situation, the different values of the header could be used to identify what is really needed by the server, instead of sending the whole page.

I hope this answers your question.

Flags: needinfo?(echuang) → needinfo?(hamishwillee)

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.

By default 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 send_me_something_else or someting_completely_different or 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?
  • 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 true returned.

Sorry if this is a dumb question!

Flags: needinfo?(hamishwillee)
Flags: needinfo?(echuang)

(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.

By default 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 send_me_something_else or someting_completely_different or 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 true returned.

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!

Flags: needinfo?(echuang) → needinfo?(hamishwillee)

Thanks very much! That helps :-)

Flags: needinfo?(hamishwillee)

FYI, docs work pretty much complete. Just going through the last stages of review. As in a previous post, you can track this https://github.com/mdn/content/issues/13367

Thanks for all the help Evan.

You need to log in before you can comment on or make changes to this bug.