Jump to content

Load JS files only if they exist


Recommended Posts

Hello there dear people of this awesome forum!


I am hoping you can help me with a problem I have:

Let's say my game has these files:

  • main.js
  • player.js
  • hud.js

If hud.js is missing the game won't start. I need a way, so that this would only not show the hud but still execute the rest of the game.

Any tips are appreciated, thanks in advance!

Link to comment
Share on other sites

Make an ajax request to your file, looking something like this:

{  url: "./js/hud.js",

   success: function(result){
      console.log("file is there");
   error: function(){
      console.log("file is not there");



Link to comment
Share on other sites

Thanks for the answers. I will look into Ajax.

I am trying to build a programming learning environment. The player types some code in a web based IDE. These produced files shall then land in the game. So the player basically extends a basic game. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...