courses.reviews logo
I launched a free website to help you find the best courses with reviews & discounts.
Up to date
Published
3 min read

Trevor I. Lasn

Staff Software Engineer, Engineering Manager

JavaScript compile hints: what they are and when to use them

V8's compile hints let you control which JavaScript gets compiled immediately during page load

JavaScript compile hints are a new V8 feature that lets you control when your code gets compiled. By adding a simple comment to your JavaScript files, you can force V8 to compile functions immediately during script loading instead of waiting until they’re called.

wazzzup1.js
//# allFunctionsCalledOnLoad
function wazzzup1() {
console.log("Wazzzup!");
}

Note that the compile hint comment must be placed at the very top of the file. In Chrome 136, you can only mark entire files for eager compilation - individual function-level hints aren’t supported yet.

When V8 processes JavaScript, it has to decide whether to compile each function right away or defer compilation until the function is actually used. This decision impacts performance - if a function gets called during page load but wasn’t compiled eagerly, V8 has to stop and compile it on the main thread, blocking your app. The compile hints feature addresses this by letting you mark entire files for eager compilation.

Compile hints are useful for libraries or files that are critical to your app’s startup performance. By marking these files, you can ensure that all functions within them are compiled immediately, reducing the risk of blocking the main thread during page load. According to the V8 team’s testing:

Many web pages would benefit from selecting the correct functions for eager compilation. For example, in our experiment with popular web pages, 17 out of 20 showed improvements, and the average foreground parse and compile times reduction was 630 ms.

This 630 millisecond improvement can make a significant difference in how quickly your app becomes interactive.

You should avoid using compile hints on large utility libraries where only a few functions get called initially, or on code that loads conditionally. The key is identifying files where most functions actually run during page load. Compiling unnecessary code wastes memory and processing time.

Here’s a file without the compile hints so you can see the difference:

You can verify compile hints are working by running Chrome with function logging:

This will create a log file with all function events. If you see a parse-function event for a function, it means V8 compiled it lazily when it was called. Functions compiled eagerly (with the compile hint) won’t show this event - they’re already compiled during initial script processing.

The feature works in Chrome 136 and later. Future versions plan to support marking individual functions for eager compilation, giving even more precise control over startup performance.

Compile hints solve JavaScript startup performance issues - with minimal effort. If you have a core file that always runs during page load, adding that single comment can significantly improve your initial load times.


Found this article helpful? You might enjoy my free newsletter. I share dev tips and insights to help you grow your coding skills and advance your tech career.

Interested in supporting this blog in exchange for a shoutout? Get in touch.


Liked this post?

Check out these related articles that might be useful for you. They cover similar topics and provide additional insights.

Javascript
4 min read

JavaScript Import Attributes (ES2025)

Understanding the new import attributes syntax and why we can't rely on file extensions alone

Nov 10, 2024
Read article
Javascript
7 min read

JavaScript Operators: '||' vs '&&' vs '??'

Master JavaScript logical operators with practical examples and best practices

Oct 26, 2024
Read article
Javascript
3 min read

navigator.clipboard - The New Asynchronous Clipboard API in JavaScript

Copy and paste text, images, and files using the new navigator.clipboard API

Dec 7, 2024
Read article
Javascript
7 min read

JavaScript Truthy and Falsy: A Deep Dive

Grasp JavaScript's type coercion with practical examples and avoid common pitfalls

Oct 27, 2024
Read article
Javascript
6 min read

Understanding JavaScript Closures With Examples

Closures are essential for creating functions that maintain state, without relying on global variables.

Sep 6, 2024
Read article
Javascript
5 min read

Working with JavaScript's Scheduler API

Learn how to prioritize and control task execution in JavaScript using the new Scheduler API for better performance and user experience

Nov 26, 2024
Read article
Javascript
5 min read

Precise Decimal Math in JavaScript with Fraction.js

How to handle exact decimal calculations in JavaScript when floating-point precision isn't good enough

Nov 16, 2024
Read article
Javascript
3 min read

Float16Array in JavaScript

Understanding the new 16-bit floating point array in JavaScript

Apr 14, 2025
Read article
Javascript
4 min read

Embrace Intermediate Variables and Early Returns in JavaScript

Early returns and intermediate variables make your code easier to reason about

Aug 30, 2024
Read article

This article was originally published on https://www.trevorlasn.com/blog/javascript-compile-hints. It was written by a human and polished using grammar tools for clarity.