LibWeb: Preload resources hinted by <link rel="preload">

If a page is nice enough to give us some preload hints, we can tell
RequestServer to get started on downloading the resources right away,
instead of waiting until discovering them later on during parsing.
This commit is contained in:
Andreas Kling 2021-09-27 02:06:37 +02:00
parent ed5c807c99
commit 5bb2e6597a
Notes: sideshowbarker 2024-07-18 03:25:05 +09:00
2 changed files with 12 additions and 0 deletions

View file

@ -36,6 +36,13 @@ void HTMLLinkElement::inserted()
if (auto sheet = m_css_loader.style_sheet())
document().style_sheets().add_sheet(sheet.release_nonnull());
}
if (m_relationship & Relationship::Preload) {
// FIXME: Respect the "as" attribute.
LoadRequest request;
request.set_url(attribute(HTML::AttributeNames::href));
m_preload_resource = ResourceLoader::the().load_resource(Resource::Type::Generic, request);
}
}
void HTMLLinkElement::parse_attribute(const FlyString& name, const String& value)
@ -48,6 +55,8 @@ void HTMLLinkElement::parse_attribute(const FlyString& name, const String& value
m_relationship |= Relationship::Stylesheet;
else if (part == "alternate")
m_relationship |= Relationship::Alternate;
else if (part == "preload")
m_relationship |= Relationship::Preload;
}
}
}

View file

@ -32,9 +32,12 @@ private:
enum {
Alternate = 1 << 0,
Stylesheet = 1 << 1,
Preload = 1 << 2,
};
};
RefPtr<Resource> m_preload_resource;
CSSLoader m_css_loader;
unsigned m_relationship { 0 };
};