Skip to content

Commit a99cae0

Browse files
committed
link prefetch optimization
1 parent 3427d53 commit a99cae0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/dashboard/Data/Browser/DataBrowser.react.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -857,18 +857,18 @@ export default class DataBrowser extends React.Component {
857857
link.as = mediaType;
858858
link.href = url;
859859

860+
link.onload = () => {
861+
// Resource successfully cached, safe to remove the link element
862+
link.remove();
863+
};
864+
860865
link.onerror = () => {
861866
console.error(`Failed to prefetch ${mediaType}: ${url}`);
867+
// Failed to fetch, remove the link element
868+
link.remove();
862869
};
863870

864871
document.head.appendChild(link);
865-
866-
// Clean up the link element after a delay to prevent memory leaks
867-
setTimeout(() => {
868-
if (link.parentNode) {
869-
link.parentNode.removeChild(link);
870-
}
871-
}, 30000); // Remove after 30 seconds
872872
});
873873
}
874874

0 commit comments

Comments
 (0)