From 74a3eb2ae08907c29ab33c5f4aa9ba4d40fb54e8 Mon Sep 17 00:00:00 2001 From: blankie Date: Sat, 25 Nov 2023 14:53:34 +1100 Subject: [PATCH] Lazyload images --- routes/about.cpp | 2 +- routes/user.cpp | 4 ++-- servehelper.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/routes/about.cpp b/routes/about.cpp index 013ed2c..ae0d52d 100644 --- a/routes/about.cpp +++ b/routes/about.cpp @@ -27,7 +27,7 @@ void about_route(const httplib::Request& req, httplib::Response& res) { Element body("body", { Element("a", {{"href", instance.thumbnail}}, { - Element("img", {{"class", "about_page-header"}, {"src", instance.thumbnail}}, {}), + Element("img", {{"class", "about_page-header"}, {"loading", "lazy"}, {"src", instance.thumbnail}}, {}), }), Element("p", { Element("b", {instance.title, ":"}), " ", instance.description, diff --git a/routes/user.cpp b/routes/user.cpp index 0bba65d..4701efe 100644 --- a/routes/user.cpp +++ b/routes/user.cpp @@ -99,11 +99,11 @@ static inline Element user_header(const httplib::Request& req, const std::string Element header("header", { Element("a", {{"href", account.header}}, { - Element("img", {{"class", "user_page-header"}, {"alt", "User header"}, {"src", account.header}}, {}), + Element("img", {{"class", "user_page-header"}, {"alt", "User header"}, {"loading", "lazy"}, {"src", account.header}}, {}), }), Element("div", {{"class", "user_page-main_header"}}, { Element("a", {{"href", account.avatar}}, { - Element("img", {{"class", "user_page-profile"}, {"alt", "User profile picture"}, {"src", account.avatar}}, {}), + Element("img", {{"class", "user_page-profile"}, {"alt", "User profile picture"}, {"loading", "lazy"}, {"src", account.avatar}}, {}), }), Element("span", { Element("b", {preprocess_html(req, account.emojis, account.display_name)}), account.bot ? " (bot)" : "", " (@", account.acct(), ")", view_on_original, diff --git a/servehelper.cpp b/servehelper.cpp index df74676..a20bac9 100644 --- a/servehelper.cpp +++ b/servehelper.cpp @@ -394,7 +394,7 @@ static Element serialize_post(const httplib::Request& req, const std::string& se Element div("div", {{"class", "post"}}, { Element("div", {{"class", "post-header"}}, { Element("a", {{"href", get_origin(req) + '/' + server + "/@" + post.account.acct(false)}}, { - Element("img", {{"class", "post-avatar"}, {"alt", "User profile picture"}, {"src", post.account.avatar_static}}, {}), + Element("img", {{"class", "post-avatar"}, {"alt", "User profile picture"}, {"loading", "lazy"}, {"src", post.account.avatar_static}}, {}), Element("span", { Element("b", {preprocess_html(req, post.account.emojis, post.account.display_name)}), Element("br"), "@", post.account.acct(), @@ -423,7 +423,7 @@ static inline Element serialize_media(const Media& media) { Element element = [&]() { if (media.type == "image") { return Element("a", {{"href", media.url}}, { - Element("img", {{"src", media.preview_url.value_or(media.url)}}, {}), + Element("img", {{"loading", "lazy"}, {"src", media.preview_url.value_or(media.url)}}, {}), }); } else if (media.type == "video") { Element video("video", {{"controls", ""}, {"src", media.url}}, {});