Sketch is displayed twice inside my index.html page

Hi, I’m trying to run my sketches in a pretty simple webpage, just to show students how to put P5.js and index.html together and run it. What happens is that the canvas and its elements and behavior are created twice on the webpage, side by side. I have no clue of what is happening…

Please help :wink:

can you show the index.html
here as posted code </> editor menu button

? do you run any server or just play

  • index.html
  • sketch.js
  • p5.js

in a directory
and with double click on index.html
a browser open it?

1 Like

Thanks for such a quick response.
Let me try to tell you how I am running it:

I am running on a chromebook, using quantum as editor and web server for chromebook to display it - both from web store for Chrome. So I just refresh the page to see results of saved changes.
Because I am using a chromebook, we do not have a local library, but we are calling it via CDNJ. I will post the index.html here as well as my sketch code.

I truly appreciate you taking your time to help me. So many thanks!!

1 Like

yes , if you call the sketch.js 2 times
in index.html you see it 2 times!

also we now use newer version of p5.js

/*! p5.js v0.10.2 October 14, 2019 */

ok you could use
insofar @GoToLoop tip is better you would get the very new version automatically.

and a small comment on your code:
the background thing should be in draw
in setup it makes only sense

  • for painting sketches or
  • together with the noLoop(); command
  • if no draw loop at all

Hi… is the sketch being called twice? Sorry… I dont spot it… can you show me where so that I can remove it?

Thanks so much for your help. :wink:

My advice is to begin w/ a minimum runnable “index.html” template file like this 1: :bulb:

<script defer src=></script>
<script defer src=sketch.js></script>

Once verified it’s working, you can add more stuff to it little by little. :sunglasses:

Here’s some online sketch using this very same minimum template: :smile_cat:

how i can show you , you posted a picture and not a code,
read your index.html
and see 2 lines
one with



and they possibly are same, was my guess.

      <title>JS P5.JS Coding</title>
    <script language="javascript" type="text/javascript" src=""></script>
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <script src="sketch.js"></script>

I have removed the script.js mention and it is still displaying two canvas…

but you still call the old and the new p5.min.js

    <script language="javascript" type="text/javascript" src=""></script>
    <script src=""></script>

delete the second ( old ) line

and make sure to have a browser restart

not related, but also mixing it
with old versions for DOM and SOUND would also not work
delete that lines too

   <script src=""></script>
    <script src=""></script>

and move the background line
? no idea but worst case you resize the canvas and see 2 circles because actually
you draw 60 of them every second… but usually on the same place!!

1 Like

However, would grab the full version, which is useful only when we’re in the debugging phase. :bug:

For deploying, is a much better fit, b/c it grabs the minified version: :cowboy_hat_face:

<script defer src=></script>
<!--<script defer src=></script>-->
<script defer src=sketch.js></script>
1 Like

Thank you so much!
I will follow your recommendations and will let you know how it went.

Thanks a bunch!!

I have just removed the lines you asked me to, and it worked!!

Thank you so much again!

Thanks again, you made a huge difference for me & my students!