mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Block rendering until linked stylesheets are loaded
This commit implements the main "render blocking" behavior for link elements, drastically reducing the amount of FOUC (flash of unstyled content) we subject our users to. The document will now block rendering until linked style sheets referenced by parser-created link elements have loaded (or failed). Note that we don't yet extend the blocking period until "critical subresources" such as imported style sheets have been downloaded as well.
This commit is contained in:
parent
5146bbe296
commit
043e96946f
Notes:
github-actions[bot]
2025-02-27 20:37:32 +00:00
Author: https://github.com/awesomekling
Commit: 043e96946f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3720
5 changed files with 52 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2024, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2020-2025, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
||||
* Copyright (c) 2023-2024, Shannon Booth <shannon@serenityos.org>
|
||||
*
|
||||
|
@ -30,6 +30,7 @@
|
|||
#include <LibWeb/HTML/HTMLFormElement.h>
|
||||
#include <LibWeb/HTML/HTMLHeadElement.h>
|
||||
#include <LibWeb/HTML/HTMLHtmlElement.h>
|
||||
#include <LibWeb/HTML/HTMLLinkElement.h>
|
||||
#include <LibWeb/HTML/HTMLScriptElement.h>
|
||||
#include <LibWeb/HTML/HTMLTableElement.h>
|
||||
#include <LibWeb/HTML/HTMLTemplateElement.h>
|
||||
|
@ -781,6 +782,12 @@ GC::Ref<DOM::Element> HTMLParser::create_element_for(HTMLToken const& token, Opt
|
|||
// 9. Let element be the result of creating an element given document, localName, given namespace, null, is, and willExecuteScript.
|
||||
auto element = create_element(*document, local_name, namespace_, {}, is_value, will_execute_script).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
// AD-HOC: Let <link> elements know which document they were originally parsed for.
|
||||
// This is used for the render-blocking logic.
|
||||
if (local_name == HTML::TagNames::link && namespace_ == Namespace::HTML) {
|
||||
as<HTMLLinkElement>(*element).set_parser_document({}, document);
|
||||
}
|
||||
|
||||
// 10. Append each attribute in the given token to element.
|
||||
token.for_each_attribute([&](auto const& attribute) {
|
||||
DOM::QualifiedName qualified_name { attribute.local_name, attribute.prefix, attribute.namespace_ };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue