| Reference | Downloads | Github

psychJS.downloadResources is not blocking

URL of experiment:

Description of the problem:

I have an experiment with a set of many possible video and image resources, and we are trying to use CSV files to specify which set of trials to load for a given user.

I have written code that will use the experiment setting dialogue box to select the correct CSV and read it as a resource list (an array of JS objects with “name” and “path” fields) at the beginning of the experiment.

The first routine in the experiment is a loading screen, an in the code module, at the “Begin Routine” stage, I pass this resource list into the function psychoJS.downloadResources().

This works, the resources are loaded, it takes about 1-2 minutes. However, during this time, the experiment continues, and if it reaches a trial where it needs a resource that isn’t yet loaded it will crash. In order for the experiment to work, I need the loading screen to stay up until all the resources have been downloaded.

In the Pavlovia documentation, it states that a call to this function is blocking, so the experiment should pause until it is finished. It doesn’t seem to be doing that.

Is there some step that I’m missing?

Thanks for any help!

I’m also in the same situation. I also noticed that downloadResources does not seem to be blocking. Have you resolved your issue? Is there a way how we can make it blocking perhaps? I’m thinking of just putting a “sham” loading screen for some time, just to ensure that everything is downloaded (in all probability)… Thanks!

No, unfortunately I didn’t manage to resolve this issue. I did add a fake loading screen, but in our case it was difficult to nail down a time that would account for various download speeds that users would see. It would end up being >5 minutes, so we just found a workaround by making several smaller experiments with a limited number of video resources.

Hmm ok thank you!

So I’m trying to understand what the function does exactly… Does it continue to download the files every time there isn’t anything happening during the experiment? I found that leaving the instructions screen for longer does not seem to help with the issue, which it should…

I wonder if there’s a way to test whether a file has been downloaded without provoking an error. If so, then the loading screen could stay up until the key file(s) were valid.

1 Like

As far as I could tell, when that function is called, it will begin downloading the resources in the list argument, but it will simply continue running the experiment. When I opened the browser console, I could see the files loading in the background.

The problem I kept encountering is that if you get to a point where a resource is called, but it hasn’t been downloaded yet, then the experiment will crash.

Yes I agree some way to query whether the resource was downloaded is probably the best way around this issue.

1 Like

It may be as simple as


where testFile is the final file to be downloaded (or the one needed most urgently)

1 Like

@jdkai Thank you for your comment! I’m very new to JS and online experiments and didn’t know about the console… Using it allowed me to find the cause of my bug which was that the files of the last trials simply didn’t download! Not sure why. But I changed my code and now they’re downloading. And so everything should get downloaded on time. Thanks!

But yeah @wakecarter something like this would be nice, or just the possibility of using some synchronous download function…