# Compile script before running through code

**URL:** https://discourse.julialang.org/t/compile-script-before-running-through-code/90844
**Category:** General Usage
**Created:** [November 26, 2022, 10:50am UTC](https://discourse.julialang.org/t/compile-script-before-running-through-code/90844 "2022-11-26T10:50:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Michael\_Hecht](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michael_hecht/32/38468_2.png) [@Michael\_Hecht](https://discourse.julialang.org/u/Michael_Hecht)
#### Post date: [November 26, 2022, 10:50am UTC](https://discourse.julialang.org/t/compile-script-before-running-through-code/90844/1 "2022-11-26T10:50:36Z")

</div>

Is it possible to compile a script before passing each line? My impression is that the code is compiled line by line.

I want to start a server that does some calculations. When start the server, all code should be compiled so that the first user hasn’t to wait.

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [November 26, 2022, 11:22am UTC](https://discourse.julialang.org/t/compile-script-before-running-through-code/90844/2 "2022-11-26T11:22:13Z")

</div>

The compilation unit in Julia is a function, so you should probably place the contents of your script in a function and precompile that.

---

<div class="post-metadata">

### Author: ![Michael\_Hecht](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michael_hecht/32/38468_2.png) [@Michael\_Hecht](https://discourse.julialang.org/u/Michael_Hecht)
#### Post date: [November 26, 2022, 11:53am UTC](https://discourse.julialang.org/t/compile-script-before-running-through-code/90844/3 "2022-11-26T11:53:45Z")

</div>

Ok, the code is in a function. Do I have to add a special command in the source to force full compilation?

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [November 26, 2022, 12:07pm UTC](https://discourse.julialang.org/t/compile-script-before-running-through-code/90844/4 "2022-11-26T12:07:45Z")

</div>

There are ways to achieve this, as hinted at in my post in your other thread. Maybe this is of interest to you:

> **[SciML: Open Source Software for Scientific Machine Learning](https://sciml.ai/news/2022/09/21/compile_time/)**
>
> Open Source Software for Scientific Machine Learning
