Skip to content

Commit

Permalink
add an example to intro
Browse files Browse the repository at this point in the history
  • Loading branch information
marjakh authored Oct 11, 2024
1 parent 1d7d7d4 commit f871019
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ feedback on the proposed solution. It has not been approved to ship in Chrome.

This proposal introduces a new magic comment that signals to browsers that the functions in a JavaScript file are likely to be needed by the website. This allows the browser to parse and compile them eagerly, which can improve page load times.

In this example, the magic comment is used for triggering the eager compilation of the two JavaScript functions in the file:
```JavaScript
//# eagerCompilation=all

function foo() { ... } // will now be eagerly parsed and compiled
function bar() { ... } // will now be eagerly parsed and compiled
```

### On JavaScript parsing and compilation

Knowing which JavaScript functions to parse and compile during the initial script compilation can speed up web page loading.
Expand Down Expand Up @@ -90,9 +98,6 @@ We propse adding the following magic comment to trigger eager compilation of all

```JavaScript
//# eagerCompilation=all

function foo() { ... } // will now be eagerly parsed and compiled
function bar() { ... } // will now be eagerly parsed and compiled
```

The magic comment is intended as a hint to the browser. It signals the functions in this JS file should be treated as "high priority" - for example, compile them immediately when processing the script, as opposed to when a function is called.
Expand Down

0 comments on commit f871019

Please sign in to comment.