{"id":273,"date":"2021-06-07T16:31:37","date_gmt":"2021-06-07T15:31:37","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/?page_id=273"},"modified":"2021-06-07T22:16:20","modified_gmt":"2021-06-07T21:16:20","slug":"where-to-store-javascript","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/javascript\/where-to-store-javascript\/","title":{"rendered":"Where to store JavaScript"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright wp-image-197\" src=\"https:\/\/glow-prod-sh.s3.eu-west-1.amazonaws.com\/sh\/public\/ahscomputinghtml\/uploads\/sites\/3275\/2021\/06\/05211153\/sqa-h-150x150.png?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&#038;X-Amz-Security-Token=IQoJb3JpZ2luX2VjEMX%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCWV1LXdlc3QtMSJIMEYCIQCGTTXPyjE0ftqbsFzvv2opi0Wgxs1kx3rZUJIQ%2B83MKwIhAJ9tc9TDjOyPtJnVpKUp6CnE%2BxFUY86gW19w%2B9YvuysrKsIFCI3%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEQBRoMMjczNTcwMTk1NDMzIgwN7abrRE5IzjkP1wYqlgXGJ%2FK6eoz%2BMmOUczKFi2JXVEiS5SxLgcBTQWroAznZIhB55ibADLqgtow7PIEebhdIcW7J6H3NGz9baofzvhPFWt8%2B99DfnNcIyhVdWQ%2F%2FghxWpDA0hvkLUvRL2odehKgeHiYDE4edYqRtxNeZCB%2B8ZkpzsxQtnlZAE0OEOD8JGoUwVGXzrnr%2FDicYT55LIgYwGUMAbrPohqKqUrVhr6MQSYdTtulQ7m7wc2mPIIymVmgTGkvFc2S2tLzJZMiKSvg1fzyjTnL9oBR%2BWWg7tBGYg9hQCWdTWHxJKh2K5Z07gdKOSvF36K7hivfN59Wr2HyJw9qjFpN6%2F0hSfFdKmhiNQf3nxhDDEUXVKwEVi9icFaiYyREZ1zpBrXTFyxEj5eGRvSEX4sbVcEIvHrieaW7rSI8wofkrBcp%2B6VbODK7AOt419Hbe48UqxXX6CDOvshYcjTGzeZlZahHmMuLsA%2BGbf2SGNfZCHqYiI3GP4FpTAmSUAYNv%2BKceR1HSUTqgdg4qF5zqJ9u8Mcjkwa%2FgBy97sNMZg15DAtzFbZMz1KGPpaPPaif3BTKxjexBn5AP5hlxE%2BfkW9nNonJpcIOyWpkDXGvTT7dA3ycyseJ7DlYD%2BX6Npv%2BdA89dnq8WC%2B8X%2BYoJ%2F86DQ5ISBXUw%2ByYcU4gnCIq6p3Q8Dv0xXCMho7dd5%2B2A6xP3j4EeC%2FowHuJmiYp4B9RPryPEWMd70ZlPJb3hWA0Cb3zpZERd5JDaW2V3Uk3ajq8PZQsZL8zAnNS8IFa3%2B8jxU0xejsaho9Oua2Nw%2BqMbrz4d7NQPZBeKnN0TWqJHiQjHAWjrcQJoHofXjdlqUqnxIva0tU%2BIB7%2FtBz3FK0bws%2FMe6F7TS9nMrO%2F%2B%2BAhOk1HkQzC5vqHQBjqwAa4Tc97kE1aAVm4KPVG%2B9H6VVZ7GRG1SsBoMEPxn4Mjp3I1cZ6qQH1Zf1iEpX4VZpejXwkJCLPFkLfK%2BxToVYuhcNeR%2FxyNOSetC%2FAEbSwzyd0oQXjub%2F86qj8oocDPB0yw1azp94nspBNkQB8nqGGsJjqJ3LlR7STAh%2Fxhk3hZNN98AemCKGbd9mjzEjuMR24fYYZDMpGVRnLcVGzm8%2B9nIA%2Fin52wgFFm32n75Sbg4&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47U6V5GPIC7%2F20260516%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20260516T121546Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=82495968376b84637eabc6c41a27336cc3343f35ef25465f9d5dd037d9b0cd3f\" alt=\"\" width=\"100\" height=\"97\" \/>As with CSS, JavaScript can be placed inside HTML elements, within an HTML file, or in a separate file.<\/p>\n<p>&nbsp;<\/p>\n<h1>Inline JavaScript<\/h1>\n<p>The JavaScript code to respond to an event is written inside the HTMl element.<\/p>\n<p>This is only suitable for very simple scripts.<\/p>\n<pre class=\"brush: xml; title: HTML body; notranslate\" title=\"HTML body\">\r\n&lt;button onclick=&quot;alert('You clicked me!')&quot;&gt;Click Me&lt;\/button&gt;\r\n<\/pre>\n<h1>Internal JavaScript Code<\/h1>\n<p>All JavaScript functions are written in a &lt;script&gt; block, often placed inside the &lt;head&gt; block for maintainability. A script block can contain multiple functions.<\/p>\n<p>Events then call these functions.<\/p>\n<p>Note: Program\/Text editors will use syntax highlighting for HTML, leaving the &lt;script&gt; blocks unformatted &#8211; and harder to debug.<\/p>\n<pre class=\"brush: xml; title: HTML head; notranslate\" title=\"HTML head\">&lt;script&gt;\r\n    function showCopyright() { \r\n        alert(&quot;This page is copyright A Person 2021&quot;); \r\n    }\r\n&lt;script&gt;<\/pre>\n<pre class=\"brush: xml; title: HTML body; notranslate\" title=\"HTML body\">&lt;button onclick=&quot;showCopyright()&quot;&gt;Copyright&lt;\/button&gt;<\/pre>\n<h1>External JavaScript File<\/h1>\n<p>If you will use the same scripts across several pages, then save them in a separate file &#8211; <strong>myscripts.js<\/strong><\/p>\n<p>Add a link to the file in the &lt;head&gt; of the HTML:<\/p>\n<pre class=\"brush: jscript; title: myscripts.js; notranslate\" title=\"myscripts.js\">\r\nfunction showCopyright() { \r\n    alert(&quot;This page is copyright A Person 2021&quot;); \r\n}<\/pre>\n<pre class=\"brush: xml; title: HTML head; notranslate\" title=\"HTML head\">&lt;script src=&quot;myscripts.js&quot;&gt;&lt;\/script&gt;<\/pre>\n<pre class=\"brush: xml; title: HTML body; notranslate\" title=\"HTML body\">&lt;button onclick=&quot;showCopyright()&quot;&gt;Copyright&lt;\/button&gt;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As with CSS, JavaScript can be placed inside HTML elements, within an HTML file, or in a separate file. &nbsp; Inline JavaScript The JavaScript code to respond to an event is written inside the HTMl element. This is only suitable for very simple scripts. &lt;button onclick=&quot;alert(&#8216;You clicked me!&#8217;)&quot;&gt;Click Me&lt;\/button&gt; Internal JavaScript Code All JavaScript functions are written in a &lt;script&gt; block, often placed inside the &lt;head&gt; block for maintainability. A<\/p>\n<p><a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/javascript\/where-to-store-javascript\/\">Read More<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"parent":259,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-273","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages\/273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/comments?post=273"}],"version-history":[{"count":14,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages\/273\/revisions"}],"predecessor-version":[{"id":294,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages\/273\/revisions\/294"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages\/259"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/media?parent=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}