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

Unified Diff: Source/core/dom/ScriptLoader.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/dom/ScriptLoader.h ('k') | Source/core/fetch/FetchRequest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/ScriptLoader.cpp
diff --git a/Source/core/dom/ScriptLoader.cpp b/Source/core/dom/ScriptLoader.cpp
index f69e0e63d362e4750b5f16bbce060813de6b7058..4dea7b47e475275550b62de50658a5a59fdaef79 100644
--- a/Source/core/dom/ScriptLoader.cpp
+++ b/Source/core/dom/ScriptLoader.cpp
@@ -65,6 +65,8 @@ ScriptLoader::ScriptLoader(Element* element, bool parserInserted, bool alreadySt
, m_readyToBeParserExecuted(false)
, m_willExecuteWhenDocumentFinishedParsing(false)
, m_forceAsync(!parserInserted)
+ , m_hasAsyncAttribute(false)
+ , m_hasDeferAttribute(false)
, m_willExecuteInOrder(false)
{
ASSERT(m_element);
@@ -100,6 +102,7 @@ void ScriptLoader::handleSourceAttribute(const String& sourceUrl)
void ScriptLoader::handleAsyncAttribute()
{
m_forceAsync = false;
+ m_hasAsyncAttribute = true;
}
// Helper function
@@ -184,6 +187,9 @@ bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy
if (wasParserInserted && !client->asyncAttributeValue())
m_forceAsync = true;
+ if (client->deferAttributeValue())
+ m_hasDeferAttribute = true;
+
// FIXME: HTML5 spec says we should check that all children are either comments or empty text nodes.
if (!client->hasSourceAttribute() && !m_element->hasChildren())
return false;
@@ -267,6 +273,9 @@ bool ScriptLoader::fetchScript(const String& sourceUrl)
if (scriptPassesCSP)
request.setContentSecurityCheck(DoNotCheckContentSecurityPolicy);
+ if (!m_parserInserted || m_hasAsyncAttribute || m_hasDeferAttribute)
+ request.setExecAsync(true);
+
m_resource = elementDocument->fetcher()->fetchScript(request);
m_isExternalScript = true;
}
« no previous file with comments | « Source/core/dom/ScriptLoader.h ('k') | Source/core/fetch/FetchRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698