polymer et jquery

94 views
Skip to first unread message

tanda...@gmail.com

unread,
Sep 2, 2015, 1:40:44 PM9/2/15
to Polymer
Salut a tous,  quelqu'un a une idée de la façon dont utiliser jquery dans les web components de google?

Eric Bidelman

unread,
Sep 2, 2015, 1:56:39 PM9/2/15
to tanda...@gmail.com, Polymer
You can create an html import for jquery.js, similar to what https://github.com/PolymerElements/marked-element/blob/master/marked-import.html does for marked.js and import that as a dependency to your element. Like this.

On Wed, Sep 2, 2015 at 10:40 AM <tanda...@gmail.com> wrote:
Salut a tous,  quelqu'un a une idée de la façon dont utiliser jquery dans les web components de google?

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/f50b3eb9-5cad-42e4-8afe-2f5372f187ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kun Li

unread,
Sep 4, 2015, 5:10:29 PM9/4/15
to Polymer, tanda...@gmail.com
What is the advantage of doing this instead of just include "<script src='../marked/lib/marked.js'></script>" into the element script section?

Eric Bidelman

unread,
Sep 4, 2015, 5:47:07 PM9/4/15
to Kun Li, Polymer, tanda...@gmail.com
 If you use that script in another place in your app, it's going to load + execute  again. Using an import will de-dupe the URL and prevent that.

Kun Li

unread,
Sep 4, 2015, 7:43:52 PM9/4/15
to Eric Bidelman, Polymer, tanda...@gmail.com
Thanks for your answer Eric.

In our project, we load all global javascript files in the root level "index.html" file, which also imports the element.html file which includes all the components related import. Then we assume that all components can safely use the variables in those global javascript files. Plus, all the non-polymer codes can also use those global variables.

It's working so far, but I wonder if you see hidden trap of this approach. One thing I'm not sure is, since element.html is imported in the head, while all the global javascript files are loaded in the end of body, could it be possible that when Polymer components are ready, some of the js files are not loaded yet, hence the error of undefined variable could happen?

Thanks in advance!

Eric Bidelman

unread,
Sep 6, 2015, 6:59:51 PM9/6/15
to Kun Li, Polymer, tanda...@gmail.com
You're in control of the app, so if that setup works for you, go for it! We usually recommend people load any element dependencies in the same html import that defines the <dom-module>. This makes the element portable and resuable, but that might not be a requirement for your project.

Kun Li

unread,
Sep 7, 2015, 1:30:16 AM9/7/15
to Eric Bidelman, Polymer, tanda...@gmail.com
That makes sense. Thanks again for your reply!
Reply all
Reply to author
Forward
0 new messages