How to work with text files

I’d like to use three text files to convert an integer to a string for a game UID. Is it best to keep the files as-is and upload to the server or just to copy and paste them into my Elm files? They will be static, once complete.

1 Like

The browser doesn’t allow you to read local files unless the user specifically chooses one via a file input. This is not the experience you want for a game.

Hosting the files on a server and pulling them down via HTTP at app boot is a fine solution. You may have to put some sort of loading spinner on the game while you wait for these files to be loaded. This allows you some flexibility in modifying the files without needing to recompile the game.

Since they are static, keeping the text in your Elm program is probably the easiest way to deal with them. If they are some form of config, you might end up converting them from raw text into some richer types that describe the different options.

2 Likes

You can use something like IndexedDB to simulate a local file system. it works in all major browsers (support is partial).

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.