Detecting if the script has been added to the DOM

37 views
Skip to first unread message

Karan Goel

unread,
May 17, 2014, 12:51:24 PM5/17/14
to polym...@googlegroups.com
So say my element includes a script and the client uses my element multiple times on a single page. Is there a way to detect if the script is already on the page and thus not include the script.

Rob Dodson

unread,
May 18, 2014, 12:58:42 PM5/18/14
to Karan Goel, polymer-dev
Are you including the script with a script tag, or are you actually loading it in async?

If it's just a script tag then we recommend you place the script tag inside an html import, and link to that import at the top of your element definition

If you're loading in a library asynchronously then you could leverage core-shared-lib

With core-shared-lib, elements get notified when the dependency has loaded so they can kickoff and do their thing. We use it in the google-apis element

Which we then use in pretty much all of the elements in GoogleWebComponents


On Sat, May 17, 2014 at 9:51 AM, Karan Goel <karan...@gmail.com> wrote:
So say my element includes a script and the client uses my element multiple times on a single page. Is there a way to detect if the script is already on the page and thus not include the script.

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/b9da98d7-b4ec-405b-9d4b-5c5f24481a56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Karan Goel

unread,
May 18, 2014, 2:07:37 PM5/18/14
to Rob Dodson, polymer-dev
Oh ok. Awesome! This is super helpful. Thanks.

Karan Goel
Reply all
Reply to author
Forward
0 new messages