{"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 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=IQoJb3JpZ2luX2VjENj%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCWV1LXdlc3QtMSJHMEUCIF%2BPukkbMGyFGP7tcqAMglq0PQKX559DLc%2Fx8h9tuTdRAiEAza7rSDcGg9ol9cuB8MF8472iSoRpHtlfhR4QYnpcWc4qwgUIoP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FARAFGgwyNzM1NzAxOTU0MzMiDIjc%2BM7LgAITmMiYrSqWBXbhoCicc8MZHchb30EULNsTlTWh9X0wnf1ErNaXLQFZeRXdPQpYPR4zYYYhOIL319W1Tz2IAhSKDyABkaLCQ5PLsXd3G21s969G1Nw0s3zRPWuMnBBsbXbs8KUO1yiMwvTHKJslXHPdXKOIULX%2Bo7tE3n39COgHACFEGyMQ70frrGjSiaayebGW5eRSRZnerYLNhDyV%2Fp7I283%2BoNLJQ2CoN3N6DZZk1ibw5lVdknzuaFutfRIsyYsyEY97ceA117Dqg1OxWuGD834Dy3gpdgk8l50eRlogvo5Yobj6nWeH7RVIh%2BJ9tYGmpEUi0sIQ9jGbbsGjHpKR0njltQotKeNFh98ujjGj3Uikt4mCNKk8Gbg%2BheOZ6dsUt1xyIhHkY20JfWEUwUh%2Fb2QUjovMmWarHiAVqtY92i4m9lL6AmKr3GL7RALorHd8IG6kPTQGMhjWhm%2Fvk9BzrWiUplqnvIyleHAyMeLSn%2B%2FxVqlhWLDsQarrF%2BkTq0GVI906HcwAN7McW1GCe133m0UyGBFlHlTxlMF7tBMNRBjv9YnpTh7jEXrJQznK6jfZ77uDM1Uh1dtftWASNpiMmf%2FmG2tpuXjaii0YBtatOOjhT6puNH3GV%2F59rZDCJ40sgQHo1GfE0hIHDDNAFmrkmHf8wjKeSoa5agGvIEY3BhRmm4d5L%2FxrjfnHmriX3hwIItJei%2B%2BiFh9W8APvXvv%2BE4VQPpuxzTF7l2zwcl%2FDZwu8M%2Fw1C4nJt8xuANaYMtAXn3uSVfD46zg9Qh2VkaEFTkDoPPmyoGLWRMnNbc5TaqM9hl0F2Njr%2BqvERz217N6NKM%2FDfrWPr4VhA%2BJVydr%2B3ERX8uuDrD67n1TLeLkqvIOtkZ6%2FHusgZxkojTv%2BMIG1kNUGOrEB9TtcZ%2FgaLKPxySJHqCDz5jYry6NJO1MorIckFaPYpE%2FeucIgZTw1uBfUdaP8sdY7D1Hy45mcYPrgM%2F8bpIDKIQ6SXzcvZOMD2bwtdoMgKzWJ88smmCqXZx5MpgFrMryUxVcVTxU6oYGuxg6rDueldqXFT0sTVmMHMFyyvL47y3W%2BR6DkoQa36wDks7EE8MIYo3DdSw71P1fGMvRtze3%2BgH5JDPijbFo5z0Thw3c8rydr&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47UZZA4XO2P%2F20260911%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20260911T153632Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=8bf31fb41043b72ec16e57103840efe8731e1fcdacfe92b512b2803b0daa052c\" 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}]}}