polymer icon indicating copy to clipboard operation
polymer copied to clipboard

Firefox doesn't load script in template

Open JanMiksovsky opened this issue 12 years ago • 5 comments

See http://jsbin.com/huhis/1/edit. This logs the string "loaded" to the console in Chrome, Canary, and Safari — but not Firefox. (Separate bug: This displays "loaded" twice in Safari.

Background: I came across this case in trying to use a defer attribute on a script required by a analytics beacon element that would only be instantiated once per page. I wanted:

  • The beacon element to load its own script (rather than requiring the outer page to load the script separately)
  • The analytics script to be deferred to avoid delaying rendering of the page
  • Some work to be done after the deferred script eventually loaded.

I couldn't work out how to sink an event handler on the script element's load event if the script tag were outside the template. I tried putting the script tag within the template, and that at least let me sink load with on-load="{{loadedHandler}}". This worked everywhere in Firefox, which I isolated to the jsbin above.

JanMiksovsky avatar Apr 03 '14 17:04 JanMiksovsky

Script seems to work when cloning a template directly: http://jsbin.com/kesepoca/1/edit

I wonder if this has to do with ShadowDOM polyfill?

dfreedm avatar Apr 04 '14 19:04 dfreedm

Btw, I assume safari displays 'loaded' twice because we have to polyfill template element, and we can't polyfill the "script doesn't run" behavior, as the parser executes the script before the polyfill can touch the containing template element.

dfreedm avatar Apr 04 '14 19:04 dfreedm

Also btw, 'loaded twice' shouldn't happen in a import, where we can control parsing.

sjmiles avatar Apr 04 '14 19:04 sjmiles

Closing this issue due to age and the release of version 1 of Polymer - please feel free to re-open if this is incorrect.

tjsavage avatar Oct 23 '15 21:10 tjsavage

Still <script> does not get executed if placed inside any custom element in FF (in my case, in <paper-material>). But works in Chromium. Polymer versions tried: 1.1.3 and latest 1.2.1

halfstrik avatar Nov 11 '15 07:11 halfstrik