Jump to content

[SOLVED] - Dynamically Load Javascript


Recommended Posts

Are there any facilities to dynamically load javascript in babylon js...

If not what it the recommended way to load javascript from a string?

Is window.eval ok to use in a custom scene loader (like objFileLoader.ts)?

If i use window.eval to dynamically load javascript, will it be acceptable code to submit to github project?

Link to comment
Share on other sites

PR = "pull request", MackeyK24  (in case you didn't know).  It is the approved way to contribute to BabylonJS framework source @ GitHub. 

Were you talking about contributing to BabylonJS framework... via GitHub pull request?  That is why Deltakosh is asking this.

IF you were referring-to submitting a project... to YOUR GitHub repository, then no problems... use eval in your projects, if you please.   But it is wise to learn about the potential hazards of using eval.

I just wanted to clarify a possible mis-understanding.  No 'eval rules' for your own GitHub-based project.  Possibly SOME 'eval rules' for contributions to Babylon.js core.  :)

Ok bye.  :)

Link to comment
Share on other sites

I believe he meant contributing to the bjs repo in case it doesn't already have built in js loading functionality.

Mackey why would you need to use eval? Basically it should be avoided whenever possible, it's best practice to not ever use it, especially not in an open source project used by many people.

Link to comment
Share on other sites

*nod*  I'm no client-server guy, but... let's pretend the server needed to change a "world" weather condition... for all listening clients.  There's really 2 ways to handle this.

1.  Put a weather-changer function in everyone's client JS (at auth-in/initial-client-load)... and then when it's time to make it rain, send a packet (a weather-change packet-type?) to all clients... saying WHICH function to run (if it is not already TYPED as a weather change packet type), and include the needed data FOR that function... to make it rain.  In other words, send data for the already-onboard weather changer function.

2.  Send the entire make-it-rain function, in a packet... to all clients, and then "order" all clients to execute the arriving function... via eval.  This is where I would use eval... if I were me. :)  Client-side packet-handling would be very simple, this way.  Unpack the packet, and execute whatever JS was found within.

But I'm just speculating.  It's not about me.  :)


Link to comment
Share on other sites

Nevermind... I just gonna pull that little feature from the Unity Exporter/Editor plugin :)

If i anna dynamic load from string... i have had success creating

var s = document.createElement('script');

s.async = false;

s.textContent = "javascript code";


so far that works load javascript from a string


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...