Web Standard: Javascript

Definitions

JavaScript (JS) is a client-side scripting language. You can use it to validate forms, 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.

Area webmasters in the Drupal WebCMS can write JS, per page, 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; JS in any other field is stripped out
  • 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 include the master jQuery file.

Related Documents

About this Standard

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