Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit dbde989

Browse files
jeffkaufmancrowell
authored andcommitted
preload: strip existing rel=preload hints
Fixes #1327
1 parent 19cf3bb commit dbde989

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

net/instaweb/rewriter/strip_subresource_hints_filter.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ void StripSubresourceHintsFilter::StartElement(HtmlElement* element) {
5151

5252
if (element->keyword() == HtmlName::kLink) {
5353
const char *value = element->AttributeValue(HtmlName::kRel);
54-
if (value && StringCaseEqual(value, "subresource")) {
54+
if (value && (
55+
StringCaseEqual(value, "subresource") ||
56+
StringCaseEqual(value, "preload"))) {
5557
const RewriteOptions *options = driver_->options();
5658
const char *resource_url = element->AttributeValue(HtmlName::kSrc);
5759
if (!resource_url) {

net/instaweb/rewriter/strip_subresource_hints_filter_test.cc

+10
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ TEST_F(StripSubresourceHintsFilterTest, SingleResourceValidLink) {
156156
ValidateStripSubresourceHint(source, rewritten);
157157
}
158158

159+
TEST_F(StripSubresourceHintsFilterTest, SingleResourceValidPreloadLink) {
160+
const char *source =
161+
"<head><link rel=\"preload\" src=\"/test.gif\" as=\"image\"/></head>"
162+
"<body><img src=\"1.jpg\"/></body>";
163+
const char *rewritten =
164+
"<head></head>"
165+
"<body><img src=\"1.jpg\"/></body>";
166+
ValidateStripSubresourceHint(source, rewritten);
167+
}
168+
159169
TEST_F(StripSubresourceHintsFilterTest, SingleResourceExternalLink) {
160170
const char *source =
161171
"<head>"

0 commit comments

Comments
 (0)