From 7c3604fcf3ce613a22a1a87eb7cf87bf7ffc5d83 Mon Sep 17 00:00:00 2001 From: TennesseeTrash Date: Mon, 16 Jun 2025 23:01:03 +0200 Subject: [PATCH] [Tablegen] Add link elements to optimize image loading --- Libraries/Tablegen/Source/Tablegen.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Libraries/Tablegen/Source/Tablegen.cpp b/Libraries/Tablegen/Source/Tablegen.cpp index e136dd8..a7a0f6b 100644 --- a/Libraries/Tablegen/Source/Tablegen.cpp +++ b/Libraries/Tablegen/Source/Tablegen.cpp @@ -64,11 +64,9 @@ namespace Tablegen constexpr std::string ImageStyle(std::string_view indent, std::size_t index, - std::string_view imageName, - std::string_view imageFormat, + std::string_view imagePath, std::string_view extraSpecifier = "") { - std::string imagePath = std::vformat(imageFormat, std::make_format_args(imageName)); return std::format(imageStyleFormat, indent, index, extraSpecifier, imagePath); } @@ -180,6 +178,21 @@ namespace Tablegen imageWrap.append_attribute("class") = "kanji-image-wrap"; imageWrap.append_attribute("id") = std::format("kanji-{}", i); + std::string imagePath = std::vformat( + settings.ImageFormat, std::make_format_args(character.ImagePath) + ); + std::string animationPath = std::vformat( + settings.AnimationFormat, std::make_format_args(character.AnimationPath) + ); + + pugi::xml_node prefetchImage = container.append_child("link"); + prefetchImage.append_attribute("rel") = "prefetch"; + prefetchImage.append_attribute("href") = imagePath; + + pugi::xml_node prefetchAnimation = container.append_child("link"); + prefetchAnimation.append_attribute("rel") = "prefetch"; + prefetchAnimation.append_attribute("href") = animationPath; + pugi::xml_node image = imageWrap.append_child("input"); image.append_attribute("type") = "checkbox"; image.append_attribute("class") = "kanji-image"; @@ -188,9 +201,8 @@ namespace Tablegen //////////////////////////////////////////////////////////////////// // CSS //////////////////////////////////////////////////////////////////// - staticImg.append(ImageStyle(indent, i, character.ImagePath, settings.ImageFormat)); - animatedImg.append(ImageStyle(indent, i, character.AnimationPath, - settings.AnimationFormat, ":checked")); + staticImg.append(ImageStyle(indent, i, imagePath)); + animatedImg.append(ImageStyle(indent, i, animationPath, ":checked")); //////////////////////////////////////////////////////////////////// // JavaScript