Skip to content
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

If called multiple times, only insert one script #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

caub
Copy link

@caub caub commented Apr 2, 2021

No description provided.

@@ -1,5 +1,9 @@
/*! load-script2. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
module.exports = function loadScript2 (src, attrs, parentNode) {
const node = parentNode || document.head || document.getElementsByTagName('head')[0]
const existingScript = node.querySelector(`:scope > script[src="${src}"]`)
if (existingScript) return existingScript
Copy link
Author

@caub caub Apr 2, 2021

Choose a reason for hiding this comment

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

@feross this allows to cache the added script

it can be useful when you render more than once a component that uses loadScript, for example a modal component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant