# Creating a JavaScript file

It is recommended that you create a separate JavaScript (`js`) file for implementing the widget UI interaction and other operations. This increases clarity of the code and enables reuse of the code in other widgets. A widget can have as many JavaScript files as needed.

There are two ways to use an external JavaScript file through the widget's main HTML file:

- Specifying a JavaScript file that is included in the widget package

  Use the `<script>` tag as follows:

      <script type='text/JavaScript' src='JavaScript.js'></script>

- Specifying a JavaScript file that is stored in a remote location

  In this case, the JavaScript file is not included in the widget package. Specify the full URL of the JavaScript source in the `src` attribute of the `script` tag as follows:

      <script type='text/JavaScript' src='http://www.widget.server/JavaScript.js'></script>

Note: When linking to external JavaScript files in a remote location, specify the `AllowNetworkAccess` key in the `info.plist` file as `true` to allow the widget to connect to the network.

For more information on JavaScript, see the Web Runtime API reference and the JavaScript Tutorial published by the World Wide Web Consortium (W3C).