JavaScript
JavaScript is the programming language that runs inside web browsers to make pages interactive, powering things like menus that open, forms that check input, live search, maps and shopping carts.
JavaScript is the third layer of the web, alongside HTML for structure and CSS for appearance. It is the only one of the three that is a full programming language, so it can react to clicks, fetch new data and change the page without reloading it. Despite the name, it has nothing to do with Java.
JavaScript also runs on servers, through environments such as Node.js, which is why many modern sites use one language for both the visible page and the back end. The trade-off for owners is weight: every script a page loads costs download and processing time on the visitor's phone.
How it works
The browser downloads the JavaScript files referenced in the page and runs them. Scripts can listen for events, such as a tap, a key press or a scroll, and respond by changing what is on screen, sending data to a server or loading more content. When a form tells you a phone number is missing before you press submit, a script is checking it.
Running JavaScript takes real work from the device. The browser has to download the file, read it, and execute it, and while a large script is running the page cannot respond to taps. On a fast laptop this is barely noticeable; on a modest phone it is the difference between a menu that opens instantly and one that lags. Google measures this responsiveness with a metric called Interaction to Next Paint.
Most sites also load third-party scripts: analytics, chat widgets, advertising tags, booking tools and social embeds. Each is code written by someone else running on your page with the same access as your own code, so each adds weight and some risk. Frameworks such as React are large JavaScript libraries that organise how interactive interfaces are built.
Scripts can be told when to load. A script marked to load in the background, or only after the page has appeared, does far less harm than one that makes the browser stop and wait. Many of the quickest speed improvements on small sites come from changing when scripts load rather than removing features.
Example
A restaurant site loads a chat widget, two analytics tools, a social media feed and a table-booking script on every page. On a mid-range phone the menu button takes a noticeable moment to respond, and the page test flags most of the delay as third-party code.
Nobody has used the chat widget in months and the social feed duplicates what the restaurant posts elsewhere. Removing both, dropping one of the two analytics tools and loading the booking script only on the reservations page makes the site feel responsive again. The reservations page still works exactly as before, and the restaurant loses no data it was actually reading.
Why it matters for your business
JavaScript makes useful features possible, but it is one of the most common reasons small business sites feel sluggish on phones, and that sluggishness feeds into Core Web Vitals. Every widget or tracking tag is worth questioning once a year: if nobody uses it or reads its reports, it is costing you speed and adding risk for nothing. You can check this yourself by running a page through Google's PageSpeed Insights and reading the list of scripts it says take the longest.
Common mistakes
- Adding marketing and tracking scripts over the years and never removing the ones nobody uses.
- Building content that only appears after JavaScript runs, which some crawlers may not see.
- Loading every script on every page instead of only where it is needed.
- Installing scripts from unknown sources that can read everything typed into the page.
Questions people ask
Is JavaScript the same as Java?
No. They are separate languages with different purposes that happen to share part of a name for historical marketing reasons. JavaScript runs in browsers and on web servers; Java is used mainly for enterprise software and Android apps.
Can Google read content loaded with JavaScript?
Google can render JavaScript, but it may take longer and does not always succeed. Many AI crawlers do not run JavaScript at all. Important text, links and headings are safest when they are present in the HTML the server sends.
How do I know if JavaScript is slowing my site?
Run a page through Google PageSpeed Insights or the Lighthouse tool in Chrome. Both list the scripts that take the longest to load and run, and flag third-party code. Long lists of unused JavaScript are a common, fixable finding.