JavaScript/JavaScript within HTML: Difference between revisions
[checked revision] | [checked revision] |
Content deleted Content added
Grammer |
|||
Line 25:
<syntaxhighlight lang="html">
<!-- point to a file or to
<script src="myScript.js"></script>
<script src="js/myScript2.js"></script>
Line 41:
=== Remote Code Injection vs. Local Library ===
With the example <pre><code><script src="https://example.com/dist/js/externallib.min.js"></script></code></pre> you can inject remotely maintained code from the server <pre>https://example.com</pre> in your local web project. Remote code updates may break your local project or unwanted code features may be injected
=== Minified vs. Non-Minified Code ===
Minified Javascript code compresses the source code e.g. by shorting comprehensive variables like <tt>vImage</tt> into a single character variable <tt>a</tt>. This reduces significantly the size of the library and therefore reduces network traffic and response time
== External JavaSscript ==
Line 81:
== Location of <code><script></code> elements ==
The <code>script</code> element may appear almost anywhere within the HTML file. But there are, however, some best practices for speeding up a website <ref>Yahoo: [http://developer.yahoo.com/performance/rules.html Best practices for speeding up your website]</ref>. Some people suggest to locate it just before the closing <code></body></code> tag. This speeds up downloading, and also allows for direct manipulation of the Document Object Model (DOM) while it is rendered. But a similar behavior is initiated by the above
<syntaxhighlight lang="html">
|