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:
Andreas Kling 2025-02-27 15:30:26 +01:00 committed by Andreas Kling
commit 043e96946f
Notes: github-actions[bot] 2025-02-27 20:37:32 +00:00
5 changed files with 52 additions and 8 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2018-2025, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2021, the SerenityOS developers.
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2023, Srikavin Ramkumar <me@srikavin.me>
@ -43,6 +43,8 @@ public:
static WebIDL::ExceptionOr<void> load_fallback_favicon_if_needed(GC::Ref<DOM::Document>);
void set_parser_document(Badge<HTMLParser>, GC::Ref<DOM::Document>);
private:
HTMLLinkElement(DOM::Document&, DOM::QualifiedName);
@ -58,6 +60,7 @@ private:
// ^HTMLElement
virtual void visit_edges(Cell::Visitor&) override;
virtual bool is_implicitly_potentially_render_blocking() const override;
struct LinkProcessingOptions {
// href (default the empty string)
@ -152,6 +155,8 @@ private:
bool m_explicitly_enabled { false };
Optional<String> m_mime_type;
WeakPtr<DOM::Document> m_parser_document;
};
}