Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
preload: strip existing rel=preload hints
Browse files Browse the repository at this point in the history
Fixes #1327
  • Loading branch information
jeffkaufman authored and crowell committed Jul 13, 2016
1 parent 19cf3bb commit dbde989
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion net/instaweb/rewriter/strip_subresource_hints_filter.cc
Expand Up @@ -51,7 +51,9 @@ void StripSubresourceHintsFilter::StartElement(HtmlElement* element) {

if (element->keyword() == HtmlName::kLink) {
const char *value = element->AttributeValue(HtmlName::kRel);
if (value && StringCaseEqual(value, "subresource")) {
if (value && (
StringCaseEqual(value, "subresource") ||
StringCaseEqual(value, "preload"))) {
const RewriteOptions *options = driver_->options();
const char *resource_url = element->AttributeValue(HtmlName::kSrc);
if (!resource_url) {
Expand Down
10 changes: 10 additions & 0 deletions net/instaweb/rewriter/strip_subresource_hints_filter_test.cc
Expand Up @@ -156,6 +156,16 @@ TEST_F(StripSubresourceHintsFilterTest, SingleResourceValidLink) {
ValidateStripSubresourceHint(source, rewritten);
}

TEST_F(StripSubresourceHintsFilterTest, SingleResourceValidPreloadLink) {
const char *source =
"<head><link rel=\"preload\" src=\"/test.gif\" as=\"image\"/></head>"
"<body><img src=\"1.jpg\"/></body>";
const char *rewritten =
"<head></head>"
"<body><img src=\"1.jpg\"/></body>";
ValidateStripSubresourceHint(source, rewritten);
}

TEST_F(StripSubresourceHintsFilterTest, SingleResourceExternalLink) {
const char *source =
"<head>"
Expand Down

0 comments on commit dbde989

Please sign in to comment.