javascript - Is there any point in a JS file that has no functions? -
i've got olapic's api in front of me, , looks this:
<script src="https://olapic_source.net" data-olapic="olapic_specific_widget" data-instance="213598612346580671235" data-apikey="081274081760283650812734612" data-tags="product_id" async="async"> </script>
i'm keeping js out of html files wherever possible. i'm wondering if there reason put in own file, versus putting right on page.
the requirement script located inside of div class called "olapic_specific_widget"
so essentially
<div class="olapic_specific_widget"> <script src="path/to/external/file.js" type="text/javascript"> </script> </div>
which tidier
<div class="olapic_specific_widget"> <script src="https://olapic_source.net" data-olapic="olapic_specific_widget" data-instance="213598612346580671235" data-apikey="081274081760283650812734612" data-tags="product_id" async="async"> </script> </div>
and again, there point this, or should leave stuff in there? if there point it, know you're supposed take script tag out of external file. so, external file this?
src="https://olapic_source.net" data-olapic="olapic_specific_widget" data-instance="213598612346580671235" data-apikey="081274081760283650812734612" data-tags="product_id" async="async"
thanks time!
the script loaded src
url examines page , looks <script>
tag inside of <div class="olapic_specific_widget">
.
you cannot move of data-
attributes out of <script>
tag, because script loaded src
expects <script>
dom element contain data-
attributes. these settings html attributes, not javascript.
in short, <script>
tag acts in 2 different roles @ one:
a mechanism import remote script (because has
src
attribute)a collection of widget settings, specified
data-
attributes.
the remote script (that imported <script>
in role #1) reads data set in <script>
's attributes (in role #2).
Comments
Post a Comment