Web Standard: Javascript

Definitions

JavaScript (JS) is a client-side scripting language. It can validate form entries, detect user actions (such as individual keystrokes), or retrieve data from the server without interfering with the display or behavior of the open web page. JavaScript can also power entire applications, like Gmail.

EPA uses jQuery as its main JS library. This library "sits" on top of JS and makes common tasks easier. When you write in JQuery, you're still writing JS, but what used to be 50 lines may now be one or two.

We are providing a standard suite of JS files for everyone at the Agency to use. Linking to the EPA master JS files will improve our site performance, as users will cache a copy of the JS files. We're also providing a set of jQuery plugins, along with the styles required by those plugins.

Please note, all JS, in content managed by the Drupal WebCMS, will be output at the bottom of the HTML, just before the closing </body> tag. Placing scripts here speeds up epa.gov for our readers.

For more complicated JS needs, like calculators and widgets, Drupal WebCMS will allow web area webmasters to include JS as needed.

Content Requirements

  • You cannot use JS to create or modify styles for your content
  • All JS must go into the Page JavaScript field in Drupal WebCMS; no JS is allowed in the body field.
  • Web pages must not be dependent on JavaScript to work: it must be strictly an enhancement
    • Functions first check to see if an object is available. If not, then fail silently
    • HTML and JavaScript are separated: no inline event handlers
    • With JavaScript off, nothing happens; thus, <noscript> is unnecessary
  • Do not rely on JavaScript for critical functions
    • For example, if form entries must be validated before they go into a database, carry out that function on the server
  • If you offer advanced functionality and your pages cannot work the same way without JS, then, at a minimum, provide
    • a phone number or email address to get help
  • All Drupal WebCMS content will link to the master jQuery file.
    • If you want to add additional plugin functionality, you must request that those plugins be uploaded to the master repository.

Examples

About this Standard

Effective date: 09/28/2005
Date approved: 09/12/2012
Web Council review by: 09/02/2014 (or earlier if deemed necessary by the Web Council)