Javascript <script> cannot be found because it is loaded by another script

408 views
Skip to first unread message

Alexandre

unread,
Mar 18, 2021, 11:57:27 AM3/18/21
to oTree help & discussion
Hello everyone,

I am encountering a problem in OTree: I want the participants to play a Uno games for 5 rounds. I am using an UNO app for which I have several files (scripts, style, images).

After dropping everything in the _static folder, I managed to load the primary scripts, as well as the style.css, but the problem I'm encountering is that the main.js file is loading other .js files, which are then not found because they are loaded elsewhere and not in the static folder. More precisely, the error code in the console reads as follows: "Loading failed for the <script> with source « http://localhost:8000/p/kkbrzfeu/Introduction/Test_Uno/scripts/c3runtime.js ».

Below is my code for the template form:

{% extends "global/Page.html" %}
{% load otree %}

{% block title %}TEST{% endblock %}

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">

<meta name="description" content="UNO">
<link rel="manifest" href="{{ static "HTML_Uno/scripts/appmanifest.json" }}">
<link rel="apple-touch-icon" href="{{ static "HTML_Uno/icons/icon-128.png" }}">
<link rel="apple-touch-icon" href="{{ static "HTML_Uno/icons/icon-256.png" }}">
<link rel="apple-touch-icon" href="{{ static "HTML_Uno/icons/icon-512.png" }}">
<link rel="icon" type="image/png" href="{{ static "HTML_Uno/icons/icon-512.png" }}">

<link rel="stylesheet" href="{{ static "HTML_Uno/style.css" }}">
</head>
<body>
<div id="fb-root">
<noscript>
<div id="notSupportedWrap">
<h2 id="notSupportedTitle">This content requires JavaScript</h2>
<p class="notSupportedMessage">JavaScript appears to be disabled. Please enable it to view this content.</p>
</div>
</noscript>
<script src="{{ static "HTML_Uno/scripts/supportcheck.js" }}"></script>
<script src="{{ static "HTML_Uno/scripts/offlineclient.js" }}"></script>
<script src="{{ static "HTML_Uno/scripts/main.js" }}"></script>
<script src="{{ static "HTML_Uno/scripts/register-sw.js" }}"></script>
</div>
</body>

I know that main.js is initiating this file, for in the network tab, it says so. Thus, the issue is that I do not know how to specify OTree to look in the _static folder and not elsewhere. I tried to specify <script src="{{ static "HTML_Uno/scripts/c3runtime.js" }}"></script>, but without success.
Note that loading the game without OTree in a local web server yields no issues.

Can somebody know what to do?
Thank you in advance.


Chris @ oTree

unread,
Mar 18, 2021, 12:09:36 PM3/18/21
to oTree help & discussion
- This content is not inside any block. In oTree templates, all content should be inside a block, usually the content block, i.e. {{ block content }}.
- Templates should not contain elements like <head> and <body>. That is already handled by the oTree framework. "block content" means you are already inside the <body> tag.
- As for the JS import issue, i guess it depends how it's imported. There are many different ways to do importing in javascript, so the answer depends on what technique is currently being used: https://stackoverflow.com/questions/950087/how-do-i-include-a-javascript-file-in-another-javascript-file.
Reply all
Reply to author
Forward
0 new messages