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

Unified Diff: third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp

Issue 2148363002: Move document.write evaluation after standard preloads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 5 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
diff --git a/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp b/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
index 9c88682636e0ce6dd76d5c06fce08b40ab2a726c..c6b71332f0b2b4f239462469ef93a6b698532eb3 100644
--- a/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
+++ b/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
@@ -321,13 +321,19 @@ void HTMLDocumentParser::notifyPendingParsedChunks()
// after the document element is created in documentElementAvailable().
ASSERT(m_queuedPreloads.isEmpty());
ASSERT(m_queuedDocumentWriteScripts.isEmpty());
+ // Loop through the chunks to generate preloads before any
+ // document.write script evaluation takes place. Preloading these
+ // scripts is valuable and comparably cheap, while evaluating JS can be
+ // expensive.
+ for (auto& chunk : pendingChunks) {
+ m_preloader->takeAndPreload(chunk->preloads);
+ }
for (auto& chunk : pendingChunks) {
for (auto& index : chunk->likelyDocumentWriteScriptIndices) {
const CompactHTMLToken& token = chunk->tokens->at(index);
ASSERT(token.type() == HTMLToken::TokenType::Character);
evaluateAndPreloadScriptForDocumentWrite(token.data());
}
- m_preloader->takeAndPreload(chunk->preloads);
}
}
@@ -1075,13 +1081,14 @@ void HTMLDocumentParser::documentElementAvailable()
{
TRACE_EVENT0("blink,loader", "HTMLDocumentParser::documentElementAvailable");
DCHECK(document()->documentElement());
+ if (!m_queuedPreloads.isEmpty())
+ m_preloader->takeAndPreload(m_queuedPreloads);
+
for (const String& scriptSource : m_queuedDocumentWriteScripts) {
evaluateAndPreloadScriptForDocumentWrite(scriptSource);
}
m_queuedDocumentWriteScripts.clear();
- if (!m_queuedPreloads.isEmpty())
- m_preloader->takeAndPreload(m_queuedPreloads);
}
std::unique_ptr<HTMLPreloadScanner> HTMLDocumentParser::createPreloadScanner()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698