gojsexternal-scriptinline-scripting

Why Go.js doesn't work with inline script?


I have an application that cannot use external scripts references. I've always being able to use any kind of script putting it inline, but with go.js it has not being possible. Is there any particular reason for this?

Sample of code:

<script src="../release/go.js"></script>
<script src="../assets/js/goSamples.js"></script>  <!-- this is only for the GoJS Samples framework -->
<script id="code">
  function init() {
...

When I change it to

<script>
(here I copy all the content of go.js)
(here I copy all the content of goSamples.js)
</script>

the webpage doesn't work. Could this be something related to

<script id="code">

?

Thanks for the help.


Solution

  • You do not need goSamples.js, for one.

    There is nothing special about script id="code" in the context of this working. As long as go.js is parsed before

    It probably does not work because you probably are not waiting for the DOM to load before trying to execute code that creates a Diagram. The DOM needs to be loaded because the Diagram relies on the DIV existing.

    Note how all the samples have <body onload="init()">, which is calling the init() code after the body has loaded. I presume your code does not do this.