Select your language

Sign up

JavaScript (JS) is a programming language used for interactive web interfaces, server applications and development tools. On a Joomla website, JavaScript usually controls browser-side behaviour such as menus, forms, tabs and loading data without a full page reload.

Where JavaScript runs

In a browser, JavaScript works with the page through browser APIs. Outside the browser, it runs in environments such as Node.js. Capabilities depend on that environment: a server-side script does not automatically have access to a visitor’s page.

JavaScript and Java are different languages despite their similar names. ECMAScript specifies the JavaScript language, while the execution environment provides facilities such as the DOM and network APIs.

DOM, events and asynchronous operations

The DOM represents an HTML document as a structure of objects. A script can locate an element, change text or add a CSS class. Event handlers respond to actions such as clicking a button, typing or submitting a form.

Network requests are often made with fetch. Promises and async/await organise waiting for a result without blocking the interface during the request. Network failures and unsuccessful HTTP responses require separate handling. Long calculations on the main thread can still make the page unresponsive.

Modules divide a program into files with explicit imports. This makes maintenance easier and reduces reliance on global variables.

JavaScript in Joomla

Joomla extension and template developers use Web Asset Manager to register and enable scripts and manage their dependencies and versions. Assets can be described in joomla.asset.json, and a registered script is enabled with useScript.

Avoid loading the same library repeatedly from different modules or inserting arbitrary scripts into every article. When configuring an existing Joomla site, use the supported template or extension settings. After changes, check the browser console and test affected forms, menus and other controls.

Validation and security

Client-side form validation helps visitors but does not replace server-side data validation and permission checks. Visitors can modify or disable client-side code. Untrusted text must not be inserted as HTML without appropriate handling.

Summary

JavaScript adds interface behaviour and also runs outside browsers. In Joomla, load scripts with their dependencies, handle errors and retain server-side validation.

Newsletter Subscription
Enter your email address and we will keep you updated!

Joomla.center is not affiliated with or endorsed by the Joomla!® Project or Open Source Matters. The Joomla!® name and logo is used under a limited license granted by Open Source Matters, the trademark holder in the United States and other countries.