What JavaScript does on a web page
Picture a floor area calculator on a builder's website. You change the width from 4 to 5 metres, and the area changes from 12 to 15 square metres straight away. A few lines of JavaScript are listening for that change. They do the sum and write the new answer into the page, without loading another one.
The same idea is behind menus that open when you tap them, forms that check your details before sending, and maps you can drag around. Most of the interactive parts of a modern website run on it.
const width = document.querySelector("#width");const length = document.querySelector("#length");const area = document.querySelector("#area");function update() {area.textContent = width.value * length.value;01}width.addEventListener("input", update);length.addEventListener("input", update);
- ··Result updates as you typeThe script runs in the browser
- ··No new page is loadedThe page and its address stay the same
How Google reads JavaScript websites
Google crawls a page's HTML first. It then renders the page, running the scripts to see the finished result, and that second step can happen some time later. So anything that only appears once the scripts have run may take longer to be picked up.
Not every crawler renders pages at all. Some other search engines and many AI crawlers read the HTML and stop there. That's why it's safest to have your main copy, headings, and links in the HTML itself, and to use JavaScript to add to the page.
Keeping scripts light
Every script has to be downloaded, read, and run before it does anything. On an older phone, too many scripts can make a page slow to load and slow to respond when someone taps it. Scripts loaded from other companies, for things like live chat and advertising, are often the heaviest. Loading scripts only on the pages that need them, and holding back the ones that aren't urgent, helps keep a site quick.
Scripts in our free marketing tools
Our free tools run on small scripts like the calculator above, so each answer is worked out in your own browser.
Our SERP preview tool if (kind === "serp-preview") {tool.querySelector("[data-preview-title]").textContent = fields.title;tool.querySelector("[data-preview-description]").textContent = fields.description;…form.addEventListener("input", update);The preview updates as you typeOur SERP preview tool shows how a title and description might look in Google's results. Every time you type, the script reads the form, puts your words into the mock result, and counts the characters. It all happens on the page you're already on, with nothing reloading.
Our ROAS and PPC budget calculators function update() {const result =calculator.dataset.calculator === "roas"? roas(values.spend, values.revenue): ppc(values.budget, values.cpc, values.rate);…inputs.forEach((input) => input.addEventListener("input", update));Every box recalculates the resultThe ROAS and PPC budget calculators work the same way. Each box listens for a change, and the update function runs the right sum for that calculator and writes the answer into the page straight away.

