51 lines
1.0 KiB
Plaintext
51 lines
1.0 KiB
Plaintext
Long pieces of JavaScript should be located in dedicated *.js source files. This makes maintenance of both the script and the pages that use it easier. Additionally, it offers some efficiencies in serving the files, since it takes better advantage of browser caching to only re-serve the parts of a web page that have actually changed.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
With the default parameter value of 5:
|
|
|
|
[source,html]
|
|
----
|
|
<head>
|
|
...
|
|
<script type="text/javascript" language="JavaScript"> <!-- Noncompliant -->
|
|
function doTheThing(arg1) {
|
|
...
|
|
...
|
|
}
|
|
|
|
function doTheOtherThing(arg1) {
|
|
...
|
|
}
|
|
|
|
function andSoOn() {
|
|
...
|
|
}
|
|
</script>
|
|
</head>
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,html]
|
|
----
|
|
<head>
|
|
...
|
|
<script type="text/javascript" language="JavaScript" src="myLongScript.js"> </script>
|
|
</head>
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
include::parameters.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|