# Streamlining downloading resources

**URL:** <https://discourse.psychopy.org/t/streamlining-downloading-resources/17261>\
**Category:** Online experiments\
**Created:** [October 14, 2020, 7:41pm UTC](https://discourse.psychopy.org/t/streamlining-downloading-resources/17261 "2020-10-14T19:41:07Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![thomas\_pronk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/thomas_pronk/32/9531_2.png) [@thomas\_pronk](https://discourse.psychopy.org/u/thomas_pronk)\
**Post date:** [October 16, 2020, 9:39am UTC](https://discourse.psychopy.org/t/streamlining-downloading-resources/17261/2 "2020-10-16T09:39:17Z")

</div>

Hey Adam,

Better support for dynamically downloading resources is high on the 2do list for PsychoJS, For the time being, I’m working on a kind of plugin that can do this for you. This is the current state of it:

1. Works for images, not yet for spreadsheets (conditions)
2. Still need to test it on multiple platforms; probably will do that in the coming two weeks.
3. It uses rather funky programming concept, called a [closure](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures).

Having said this, below is some code that shows how it works. Create a routine that shows a text saying “One moment please…”, no end time, and add a code component with the script below.

**This part goes into Begin Routine**

```auto
var load = function(resources) {
  psychoJS.downloadResources(resources);
  return function() {
    // Check whether each resource is available
    try {
      for (var i = 0; i < resources.length; i++) {
        psychoJS.serverManager.getResource(resources[i].name);
      }
    } catch (e) {
      // Some resource not available yet; return true (continue routine)
      return true;
    }
    // All resources available; return false (end routine)
    return false;
  }
}
// StimA and StimB will be whatever image is specified via path
// You can use some code to change this per participant
window.checkProgress = load([
    {name: 'StimA', path: 'img/a.png'},
    {name: 'StimB', path: 'img/a.png'},
]);

```

**This part goes into Each Frame**

```auto
continueRoutine = window.checkProgress();

```

---

_[View the full topic](https://discourse.psychopy.org/t/streamlining-downloading-resources/17261)._
