Including local JavaScript files

Godot Version

4.5

Question

I would like to use a JavaScript library in a local file mylib.js in my Godot game. How can I configure Godot so it gets automatically included in any web exports and debugging sessions (when using “Run in Browser”) please?

In the export settings I have added <script src="mylib.js"></script> in the Head Include field. The file mylib.js is in my project folder. But when I start the game using “Run in Browser”, my browser’s JavaScript console shows an error “Failed to load resource: the server responded with a status of 404 (Not Found)”. My browser is Brave 1.85.120. Thank you!

I think it’s in the “Resources” tab in the “Export” dialog by adding “*.js” in the Filters to export non-resource files/folders.

Thanks. I tried this and I think that exports the files into the .pck file so the game can access it from res://. What I was looking for is a way to export it into the folder with the Godot-generated .html file, so it is accessible in the web browser.

I found a solution. This addon allows you to specify files that are copied on export: Copy Files On Export - Godot Asset Library

1 Like