Beginner question: using elm after optimizing to js

I’ve built an app in Elm. If I do elm compile src/Main.elm, it builds an index.html file that works very nicely when I invoke it.

Following the instructions here: Minification · An Introduction to Elm, I end up with elm.min.js which is somewhat obviously a javascript file. At the risk of sounding like a complete idiot, how do I run that?

Here’s what I’ve tried: I made a small index.html that contains for the body:

<body>

<pre id="elm"></pre>

<script src="elm.min.js"></script>
</body>

And, I tried

<body>

<pre id="elm"></pre>

<script src="elm.js">
  var app = Elm.Main.init({ node: document.getElementById("elm") });
</script>

But, neither of these worked, so I’m looking for help.

You’re very close, you need to mix both approaches like so

<body>

  <pre id="elm"></pre>

  <script src="elm.min.js"></script>
  <script>
    var app = Elm.Main.init({ node: document.getElementById("elm") });
  </script>
</body>

The first <script /> with src="elm.min.js" is saying to run the javascript code located at "elm.min.js". The second <script /> doesn’t have a src attribute so it runs the code between the opening and closing tags.

1 Like

That did the trick! Thanks very much!

See Web Apps · An Introduction to Elm , more info under the header Serve The Page.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.