Skip to content

exclude pre load & icon #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ function buildNode(
case NodeType.Element:
const tagName = getTagName(n);
let node: Element;

// exclude some js load by pre*
if (
tagName === 'link' &&
(
/prefetch|preload/.test(n!.attributes!.rel as string) &&
/\.js$/.test(n.attributes.href as string)
)
) {
node = document.createElement('noscript');
node.setAttribute('src', n.attributes.href as string);
return node;
}

// exclude icon load
if (tagName === 'link' && n!.attributes!.rel === 'icon') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the problem if we rebuild a link element with icon?

return document.createElement('link');
}

if (n.isSVG) {
node = doc.createElementNS('http://www.w3.org/2000/svg', tagName);
} else {
Expand Down