What JavaScript does on a website

HTML and CSS create a page that looks good but does nothing by itself. JavaScript makes it move. It opens the mobile menu, moves the slider, checks that you have entered a valid email address in a form, recalculates the price when you change a variant, or adds an item to the basket without reloading the page.

Tracking and advertising tools such as Google Analytics, Meta Pixel, chat windows and the cookie banner also run on JavaScript. Each of them adds another script to the site.

Why it matters

JavaScript makes things more convenient for visitors, but it has a downside. The browser has to download, process and run it, which takes time on a weaker phone. The more scripts there are, the longer the page takes to respond to the first click. Responsiveness is exactly what one of the Core Web Vitals metrics measures.

An error in one script can also block others. It happens that after a plugin update the order button stops working, even though the rest of the site looks normal.

A real-world example

A cosmetics shop had gradually installed three tracking tools, two chats, a discount pop-up and animated counters. On mobile it responded slowly and people abandoned their baskets. After removing duplicate tools and deferring less important scripts, the shop became noticeably faster without losing any important feature. Unnecessary scripts are among the most common bottlenecks I remove when speeding up a website.

Tips

  • Take stock every so often. Which scripts and tools on the site do you still really use?
  • Add tracking code through one tool, such as Google Tag Manager, rather than each one separately.
  • After updates, test a purchase from the basket all the way to the order confirmation.
  • Not every effect is necessary. If an animation does not help sales, it can go.