I've been developing with polymer and I've always put my <script>
tags inside my <dom-module>
tags. E.G:
<dom-module id="">
<template>
<style>
</style>
</template>
<script>
Polymer({});
</script>
</dom-module>
But I've also seen the <script>
tags put outside of the <dom-module>
tags. E.G:
<dom-module id="">
<template>
<style>
</style>
</template>
</dom-module>
<script>
Polymer({});
</script>
Both ways seem to work fine. Which way is considered correct though? Can you explain?
The dom-module
exists primarily so that the Polymer()
call can locate template, style, and other dom resources that belong to a registration. The script itself can live anywhere (as long as the corresponding dom-module
exists a priori).
Folks typically put the script inside the module as it provides a tidy bundle, but it remains optional.