Bug 1425310 - Implement modulepreload for link rel. r=yulia,smaug,jonco
Does perform the optional step of fetching descendants and linking: https://html.spec.whatwg.org/multipage/webappapis.html#fetching-scripts:fetch-the-descendants-of-and-link-a-module-script-2 Partially implements some new destinations ("as" attribute values) for modulepreload only (not for preload or link attribute reflection) Differential Revision: https://phabricator.services.mozilla.com/D172368
This commit is contained in:
@@ -675,12 +675,12 @@ nsresult ScriptLoader::StartLoadInternal(
|
||||
aRequest->GetScriptLoadContext()->IsTracking()));
|
||||
|
||||
if (aRequest->GetScriptLoadContext()->IsLinkPreloadScript()) {
|
||||
// This is <link rel="preload" as="script"> initiated speculative load,
|
||||
// put it to the group that is not blocked by leaders and doesn't block
|
||||
// follower at the same time. Giving it a much higher priority will make
|
||||
// this request be processed ahead of other Unblocked requests, but with
|
||||
// the same weight as Leaders. This will make us behave similar way for
|
||||
// both http2 and http1.
|
||||
// This is <link rel="preload" as="script"> or <link rel="modulepreload">
|
||||
// initiated speculative load, put it to the group that is not blocked by
|
||||
// leaders and doesn't block follower at the same time. Giving it a much
|
||||
// higher priority will make this request be processed ahead of other
|
||||
// Unblocked requests, but with the same weight as Leaders. This will make
|
||||
// us behave similar way for both http2 and http1.
|
||||
ScriptLoadContext::PrioritizeAsPreload(channel);
|
||||
ScriptLoadContext::AddLoadBackgroundFlag(channel);
|
||||
} else if (nsCOMPtr<nsIClassOfService> cos = do_QueryInterface(channel)) {
|
||||
@@ -786,7 +786,8 @@ nsresult ScriptLoader::StartLoadInternal(
|
||||
aRequest->mURI, aRequest->CORSMode(), aRequest->mKind);
|
||||
aRequest->GetScriptLoadContext()->NotifyOpen(
|
||||
key, channel, mDocument,
|
||||
aRequest->GetScriptLoadContext()->IsLinkPreloadScript());
|
||||
aRequest->GetScriptLoadContext()->IsLinkPreloadScript(),
|
||||
aRequest->IsModuleRequest());
|
||||
|
||||
if (aEarlyHintPreloaderId) {
|
||||
nsCOMPtr<nsIHttpChannelInternal> channelInternal =
|
||||
@@ -1349,9 +1350,18 @@ ScriptLoadRequest* ScriptLoader::LookupPreloadRequest(
|
||||
if (!elementCharset.Equals(preloadCharset) ||
|
||||
aElement->GetCORSMode() != request->CORSMode() ||
|
||||
aScriptKind != request->mKind) {
|
||||
// Drop the preload.
|
||||
request->Cancel();
|
||||
AccumulateCategorical(LABELS_DOM_SCRIPT_PRELOAD_RESULT::RequestMismatch);
|
||||
// Bug 1832361: Don't cancel modulepreload requests since the subsequent
|
||||
// non-preload request will wait for the preload via the module map and so
|
||||
// if the preload is cancelled, the non-preload request will fail to load.
|
||||
//
|
||||
// TODO: see if this should apply for all module requests, not just
|
||||
// modulepreload, in which case the IsLinkPreloadScript check can be removed
|
||||
if (!(request->IsModuleRequest() &&
|
||||
request->GetScriptLoadContext()->IsLinkPreloadScript())) {
|
||||
// Drop the preload.
|
||||
request->Cancel();
|
||||
AccumulateCategorical(LABELS_DOM_SCRIPT_PRELOAD_RESULT::RequestMismatch);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user