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
6 min read

AggregateError in JavaScript

Handle multiple errors at once

Sep 2, 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
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

Float16Array in JavaScript

Understanding the new 16-bit floating point array in JavaScript

Apr 14, 2025
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

Error.isError(): A Better Way to Check Error Types in JavaScript

Why the new Error.isError() method solves important cross-realm issues and provides more reliable error identification than instanceof

May 9, 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
Javascript
6 min read

setImmediate() vs setTimeout() in JavaScript

both setImmediate() and setTimeout() are used for scheduling tasks, but they work differently.

Sep 8, 2024
Read article
Javascript
3 min read

JavaScript's ??= Operator: Default Values Made Simple

A guide to using ??= in JavaScript to handle null and undefined values elegantly

Nov 5, 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.