From 8d7052b39ca21f853ed845980cd964c6ac0e3486 Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 9 Jan 2020 18:18:21 +0900 Subject: [PATCH] ignore preload and prefetch sources since all resources are embedded as data URL. --- src/html.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/html.rs b/src/html.rs index e3c29ab..cb25181 100644 --- a/src/html.rs +++ b/src/html.rs @@ -104,12 +104,19 @@ pub fn walk_and_embed_assets( let mut link_type = LinkType::Unknown; for attr in attrs_mut.iter_mut() { if &attr.name.local == "rel" { - if is_icon(attr.value.as_ref()) { + let value = attr.value.as_ref(); + if is_icon(value) { link_type = LinkType::Icon; break; - } else if attr.value.as_ref() == "stylesheet" { + } else if value == "stylesheet" { link_type = LinkType::Stylesheet; break; + } else if value == "preload" { + link_type = LinkType::Preload; + break; + } else if value == "dns-prefetch" { + link_type = LinkType::DnsPrefetch; + break; } } } @@ -181,6 +188,14 @@ pub fn walk_and_embed_assets( } } } + LinkType::Preload | LinkType::DnsPrefetch => { + // Since all resources are embedded as data URL, preloading and prefetching are unnecessary. + if let Some(attr) = + attrs_mut.iter_mut().find(|a| &a.name.local == "href") + { + attr.value.clear(); + } + } LinkType::Unknown => { for attr in attrs_mut.iter_mut() { if &attr.name.local == "href" {