The decline of JavaScript?
JavaScript is a scripting language that enables you to create dynamically updating content, control multimedia, and animate images. Over the past decade, front-end technology has seen an incredible increase in JavaScript framework adoption by developers. But due to Google’s PageSpeed analytics negatively scoring JavaScript load time on websites more recently, developers have looked to alternative solutions to improve these scores.
Here, we assess JavaScript load time, outline how to optimise JavaScript code, and take a look at whether there’s a decent alternative to JavaScript.
Why is JavaScript slow?
JavaScript is not inherently slow, but it can be slower than other lower-level languages for certain tasks. Several factors contribute to this:
JavaScript is an interpreted language, which means that the code is executed by an interpreter at runtime, rather than being compiled beforehand. This can make JavaScript slower than compiled languages because the interpreter has to translate the code into machine code every time it runs.
JavaScript uses automatic memory management, known as garbage collection. While this makes programming easier, it can also slow down performance because the garbage collector has to constantly check for unused objects and free up memory.
JavaScript is commonly used in an event-driven model. This means that the code is triggered by user interactions, such as mouse clicks or button presses. While this can make for a better user experience, it can also make the code slower because it has to constantly listen for events.
JavaScript has limited support for multithreading, which means that it can’t take full advantage of multiple processor cores. This can make JavaScript slower than languages that are designed for parallel processing.
Despite these factors, JavaScript has come a long way in terms of performance in recent years. And with advances in hardware and software technology, it continues to improve. What’s more, there are plenty of steps you can take to optimise it.
How to optimise Javascript code
So, does JavaScript slow down websites? The short answer is: if the JavaScript code is poorly optimised or contains errors, it can lead to slow loading times and negatively impact website performance.
Simple methods to speed up JavaScript load times are essential knowledge for web developers:
Delete unnecessary JavaScript, such as custom code for widgets that are no longer in use.
Downsize or remove your JavaScript library. Often, the same results can be achieved without libraries and with little extra effort. Alternatively, consider loading only part of the library, for example with jQueryUI.
Minimise blocking code. If JavaScript code is placed in the head section of a webpage, it can block other resources from loading until the code has finished executing. This can slow JavaScript load time and lead to a poor user experience.
Consider the performance impact of third-party scripts, such as those from social media platforms or advertising networks. These can slow down website loading times if they’re not optimised, or take a long time to load.
Is there a viable alternative to Javascript?
Lately, new fledgling frameworks such as Astro, Marko and Qwik, have taken the web development world by storm, all of which can be used in conjunction with JavaScript for a more optimised experience. By compiling components and routes down into pure HTML, PageSpeed scores have seen a sharp increase.
Astro framework
Anyone working in a marketing agency will be familiar with the age-old battle between designers and web developers. Designers want websites to look incredible, with all the bells and whistles, but web developers know this can slow the site down, and their priority is ensuring websites are as fast and slick as possible. Enter the Astro web framework, which enables a balance between the two.
Designed for speed, Astro allows users to pull content from anywhere and serve it fast.
The Astro framework strips the JavaScript surrounding interactive UI components (such as videos and hover effects) away, leaving small, isolated ‘islands’ in a sea of static, non-interactive HTML. Unused JavaScript is replaced with lightweight HTML, guaranteeing faster loads and time-to-interactive (TTI). As early adopters of the Astro framework, our crew members actively talk to the Astro team to discuss what we like and where we feel the framework could be improved, helping to shape how it works.
Marko framework
The Marko framework is HTML re-imagined as a language for building dynamic and reactive user interfaces. Just about any valid HTML is valid Marko, but Marko extends the HTML language to allow building modern applications in a declarative way.
Used to power high-traffic websites like ebay.com (which actually created Marko), this relatively new (but trusted) framework is easily scalable and tailored to wherever the code is going to run. It’s not a static site generator, rather it’s used to create web apps. At the moment, it’s not something we really use at TBB, as it’s more suited to businesses that might need to display data in real time, such as FMCG brands.
Qwik framework
Qwik takes a new approach to performance optimisation. This framework introduces the concept of ‘JavaScript Streaming’ where the page loads instantly and required JavaScript chunks are prefetched in a separate thread, similar to ‘buffering’ in video streaming. The prefetched code only executes upon user action, in a process called ‘Lazy Execution’. This performance boost requires no manual effort or decision-making from the developer, as this feature is pre-built into Qwik. In addition, Qwik’s Optimizer can generate JavaScript based on real-user metrics to understand the optimal way to bundle commonly used modules.
So, is JavaScript on the decline? No – it’s just that web developers (including our own) are discovering new ways to use it in order to achieve perfectly balanced and optimised websites. Think you could add to our ever-growing web development expertise? Get in touch about potential careers at TBB.
If you want to keep up to date with the crew, don't forget to sign up to our newsletter to benefit from digital marketing expertise, as well as exciting opportunities to improve your business' performance.
Written by Alice MacLaverty
Resident wordsmith Alice is dedicated to creating top-quality content that turns heads, builds audiences, gets clicks, and makes money.
News and insights
Why listening to your PR agency in a crisis is crucial
Learn why trusting your PR agency during a crisis is crucial to protecting your reputation, and why strategic crisis communications are essential.
Read moreNews and insights
How to increase email engagement
Email engagement is critical for marketers, yet most emails never get opened. Learn how to craft the best email subject lines, boost open rates, and optimise your campaigns to connect with your audience effectively.
Read more