# Web Noob; how hard would it be to integrate julia with HTML?

**URL:** https://discourse.julialang.org/t/web-noob-how-hard-would-it-be-to-integrate-julia-with-html/48541
**Category:** New to Julia
**Created:** [October 17, 2020, 1:04pm UTC](https://discourse.julialang.org/t/web-noob-how-hard-would-it-be-to-integrate-julia-with-html/48541 "2020-10-17T13:04:33Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)
#### Post date: [October 17, 2020, 1:04pm UTC](https://discourse.julialang.org/t/web-noob-how-hard-would-it-be-to-integrate-julia-with-html/48541/1 "2020-10-17T13:04:33Z")

</div>

So I am not a web developer. Sometimes I do web stuff at work, and a little for fun. I was doing some thinking, and a question came to mind. Why _can’t_ Julia be a serverside web language like PHP?

_Please don’t judge the pseudocode here I just quickly scrapped it together_

```nohighlight
<julia>
function do_stuff_now(x)
   out.value = x*3
end
</julia>

<body>
<form name = "form1">
<input type = "text" name = "in"/>
<input type = "button" value = "do it" onclick="do_stuff_now(form1.out.value)"/>
<input type = "text" name = "out"/>
</form>
</body>

```

How much of that has to happen in the browser vs how much of that has to happen serverside? If julia were to run clientside I see that as being very browser heavy and wades into politics, but, I think it would be very possible to allow the julia to run on the server instead and get the same behaviour, but, at greater cost to the host…

Server-side: I can imagine we could sort of parse html(remove ref’s to `<julia>...</julia>`) , get the DOM for each page. Stand up either julia microservices via post commands, or use something like Genie to host with the code baked in. Something like a “compiled” website…

Issues here would be things like security, and also, what if you had 200\_000 users all executing functions. Kind of like a reverse proxy nightmare. But maybe that’s not too different from a language like PHP?

Hoping to learn something here, color me clueless,

---

<div class="post-metadata">

### Author: ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)
#### Post date: [October 17, 2020, 1:17pm UTC](https://discourse.julialang.org/t/web-noob-how-hard-would-it-be-to-integrate-julia-with-html/48541/2 "2020-10-17T13:17:16Z")

</div>

I would suggest you split things into three parts:

- Do you want a templating engine that intermixes Julia and HTML?
- Do you want to build a web service or full server using Julia?
- Do you want a DSL to generate HTML in Julia?

There’s no reason to couple those three and they all have viable strategies in Julia, although some would be far easier than others.

---

<div class="post-metadata">

### Author: ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)
#### Post date: [October 17, 2020, 1:46pm UTC](https://discourse.julialang.org/t/web-noob-how-hard-would-it-be-to-integrate-julia-with-html/48541/3 "2020-10-17T13:46:58Z")

</div>

I think what I am most interested in would be a templating engine that intermixes Julia and HTML. Most similar to PHP. The only way I can think of that working, would be via a DSL(parsing HTML and writing off new code) and/or having the server be almost pure Julia? Is there a smarter approach? Are there discussions about this anywhere? I am likely missing good search terminology.

---

<div class="post-metadata">

### Author: ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)
#### Post date: [October 17, 2020, 2:06pm UTC](https://discourse.julialang.org/t/web-noob-how-hard-would-it-be-to-integrate-julia-with-html/48541/4 "2020-10-17T14:06:32Z")

</div>

Never tried myself, but maybe you can do this with [Genie.jl](https://genieframework.github.io/Genie.jl/dev/guides/Working_With_Genie_Apps.html#HTML-views).

---

<div class="post-metadata">

### Author: ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)
#### Post date: [October 17, 2020, 2:06pm UTC](https://discourse.julialang.org/t/web-noob-how-hard-would-it-be-to-integrate-julia-with-html/48541/5 "2020-10-17T14:06:48Z")

</div>

I think there’s two classes of template engines:

- Run-time templating, which evaluates all of the Julia code in the template per-request. This is the PHP model and the default model for [Jinja](https://jinja.palletsprojects.com/en/2.11.x/), which is probably a good example to follow.
- Ahead-of-time templating, which evaluates all of the Julia code in advance. This is the logic of template engines used for rendering static websites: Jinja can be used this way and there many [static site generators](https://wiki.python.org/moin/StaticSiteGenerator) built on top of Jinja.

Whether you need to have the server invoke Julia really depends on whether you’re committed to run-time templating.

---

<div class="post-metadata">

### Author: ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)
#### Post date: [October 17, 2020, 2:34pm UTC](https://discourse.julialang.org/t/web-noob-how-hard-would-it-be-to-integrate-julia-with-html/48541/6 "2020-10-17T14:34:05Z")

</div>

@jbrea - you are right the idea is similar to Genie. The difference is, the intent here is to abstract away the nuances of hosting pages, and all the Genie specific stuff. So kind of like a layer above Genie.

@johnmyleswhite - thanks for this I have some reading to do. Might come back with more questions later on in the week :).
