403 errors resolved - itch.io handles path resolution always relative to the index.html file.


So after a longer trial an error period, I managed to get the game to play correctly in the browser. The previous issue was that game resources were not loaded and accessing the resource URL returned a 403 error message. 


So what was the issue?

Previously I have structured my project like this: 

index.html

- assets (contains music and text assets)

- dist (contains main .js file, loads resources from assets path, on the same hierarchy level as assets)


So my main .js file would go up on hierarchy instance and then go into the assets folder. This worked just fine when testing it on a local server, but didn't when I put the game on itch.io. The structure I had was like this: 

The index.html file loads this file which contains the game logic:

libs/floppy-jam.js

and in the floppy-jam.js file the paths to resources were used like this:

../assets/texts/imgs/background.txt

at first I thought that I am unable to use 

../

but what really happened is that itch.io resolves the path relative to the index.html file. Since I had my javascript file in a sub folder and set my resource paths relative to the folder the javascript file was in it didn't work (although it does when I try to host the game locally with a node.js server instance). 

Huge thanks to the Admin leaf who gave me a proper answer to the problem. Here is his statement: 

../ does work, but path resolution happens where the HTML file is, not where the js file is. This is because the HTML file is the page executing the Javascript. You can see this by looking at the URL for the request that returned a 403: https://v6p9d9t4.ssl.hwcdn.net/html/assets/texts/imgs/background.txt The URL does not include your project's id after the /html/ path, so its' going up one more directory than you expect. Hope that helps.


Now I have restructured the path of the floppy-jam.js file to be on the same level as the index.html file, so I can use the same paths locally as well as for the itch.io hosting. The path I use for loading the .js file from index.html is now just:

floppy-jam.js

and from the floppy-jam.js file I use following path to load resources: 

./assets/texts/imgs/background.txt


Now users will be able to play the game (even though the floppy-jam version of it has very little content)   :-)

Get ASCIIVenture

Leave a comment

Log in with itch.io to leave a comment.