JavaScript
What is JavaScript?
JavaScript is the programming language that adds behaviour to a page: menus, filters, validation, maps, anything that reacts without a reload. It runs in the visitor’s browser, so every kilobyte of it costs loading time on a phone — which is why the useful question is not whether to use it but how little is enough.
What it is used for
- Interaction: menus that open, filters in a shop, a gallery, a calculator, checking a form while it is filled in.
- Loading data without a reload: more products as you scroll, live stock levels, search suggestions.
- Measurement and marketing tools: analytics, ad pixels, chat widgets, cookie banners. These are third-party scripts, and often the heaviest part of a page.
- Whole applications that run in the browser, from an online editor to a customer portal.
It runs on the visitor’s device. On a powerful laptop that is invisible; on a mid-range phone every extra script is time the visitor waits and the page does not respond.
Example
A company site built on a page builder loads 1.4 MB of JavaScript on every page: a slider library, animations, three tracking tools, a chat widget and code for features the site does not use. On a mid-range phone the page shows in four seconds but does not respond to a tap for another three, and its Interaction to Next Paint fails Google’s threshold.
A rebuild keeps the same design with 120 KB of JavaScript: a menu, a form check and the tracking, loaded after consent and after the content. The page responds as soon as it appears, and the share of mobile visitors who leave in the first five seconds halves.
Why it matters for a business
JavaScript is what makes a site feel like an application rather than a document, and it is also the most common reason a site is slow on a phone. Each script is downloaded, read and run before the page fully responds, and Google measures that delay in Core Web Vitals.
There is also a search cost. Google can run JavaScript, but later and less reliably than it reads plain HTML; text, links and prices that appear only after scripts run may be indexed late or not at all, and many AI crawlers do not run scripts at all. The main content of a page belongs in the HTML the server sends.
What to ask
- How much JavaScript does our main page load, and what does each script do?
- Which scripts come from outside tools, and are they still used?
- Do the page’s text, links and prices exist without JavaScript, in the HTML the server sends?
- How long after the page appears does it respond to a tap on a mid-range phone?
In our website development we use JavaScript where it adds something for the visitor, not out of habit: every unneeded script slows the page down on a phone.