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

Trevor I. Lasn Trevor I. Lasn
· 3 min read
Building 0xinsider.com — see who's winning across prediction markets (Polymarket, Kalshi, and more) — and what they're trading right now.

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.


Trevor I. Lasn

Building 0xinsider.com — see who's winning across prediction markets (Polymarket, Kalshi, and more) — and what they're trading right now. Product engineer based in Tartu, Estonia, building and shipping for over a decade.


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.


Related Articles

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

Javascript
7 min read

JavaScript Truthy and Falsy Values: Complete Reference

All 8 falsy values in JavaScript explained with examples. Common pitfalls with 0, empty strings, NaN, and how type coercion actually works.

Oct 27, 2024
Read article
Javascript
6 min read

setImmediate() vs setTimeout(0) in Node.js: What's the Difference?

setImmediate runs after I/O, setTimeout(0) runs after the timer phase. Here's when to use each, with event loop diagrams.

Sep 8, 2024
Read article
Javascript
3 min read

navigator.clipboard - The 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

How JavaScript Was Written Back In the Day

Have you ever been curious how JavaScript was written back in the day? I was, so I dug into some of the early frameworks and libraries to see what I could learn.

Jun 12, 2025
Read article
Javascript
6 min read

AggregateError in JavaScript

Handle multiple errors at once

Sep 2, 2024
Read article
Javascript
4 min read

Promise.try: Unified Error Handling for Sync and Async JavaScript Code (ES2025)

Stop mixing try/catch with Promise chains - JavaScript's new Promise.try handles return values, Promises, and errors uniformly

Nov 10, 2024
Read article
Javascript
4 min read

Understanding Bitwise Shifts in JavaScript: << and >>

A practical guide to left and right shift operators in JavaScript

Nov 12, 2024
Read article
Javascript
5 min read

What is the JavaScript Pipeline Operator |>

A deep dive into how pipeline operators can make your code more readable and maintainable

Oct 29, 2024
Read article
Javascript
4 min read

The Only Widely Recognized JavaScript Feature Ever Deprecated

The 'with' statement is the only feature ever deprecated in JavaScript

Aug 22, 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.