Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Unified Diff: Source/core/fetch/ResourceFetcher.cpp

Issue 457413002: Defer late and async scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Lower priorities for late/async scripts Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/fetch/FetchRequest.cpp ('k') | Source/core/fetch/ResourceLoadPriorityOptimizer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/fetch/ResourceFetcher.cpp
diff --git a/Source/core/fetch/ResourceFetcher.cpp b/Source/core/fetch/ResourceFetcher.cpp
index 14b6167d7ac605ee120b0e6ec91fb4df30c8e04b..7353742b76fae1369c72b9d24af2c9352fd291cf 100644
--- a/Source/core/fetch/ResourceFetcher.cpp
+++ b/Source/core/fetch/ResourceFetcher.cpp
@@ -119,11 +119,22 @@ static ResourceLoadPriority loadPriority(Resource::Type type, const FetchRequest
switch (type) {
case Resource::MainResource:
return ResourceLoadPriorityVeryHigh;
- case Resource::CSSStyleSheet:
- return ResourceLoadPriorityHigh;
case Resource::Raw:
return request.options().synchronousPolicy == RequestSynchronously ? ResourceLoadPriorityVeryHigh : ResourceLoadPriorityMedium;
+ case Resource::CSSStyleSheet:
case Resource::Script:
+ // CSS and Script get the same treatment and priority levels so we load them in order
+ // and they can block each other's parsing/execution (with the exception of async scripts).
+ // Async scripts do not block the parser so they get the lowest priority and can be
+ // loaded in parser order with images.
+ if (type == Resource::Script && request.execAsync())
+ return ResourceLoadPriorityVeryLow;
+ // Scripts or CSS discovered by the preload scanner that are not in the head get a low priority
+ // so they do not load while we are loading the layout-blocking resources but still load
+ // at a higher priority than images since they block the main parser.
+ if (request.forPreload() && !request.isBeforeBody())
+ return ResourceLoadPriorityLow;
+ return ResourceLoadPriorityMedium;
case Resource::Font:
case Resource::ImportResource:
return ResourceLoadPriorityMedium;
« no previous file with comments | « Source/core/fetch/FetchRequest.cpp ('k') | Source/core/fetch/ResourceLoadPriorityOptimizer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698