# Main JS file

We're going to copy most of the code from `ifc-file-reader.js` into our `main.js` file. Please note that this example is somewhat outdated. E.g. It doesn't use a scene picker.

{% tabs %}
{% tab title="ifc-file-reader.js" %}

```javascript
export function readIfcFile() {
  const input = document.querySelector('input[type="file"]');
  if (!input) return;
  input.addEventListener(
    'change',
    (e) => {
      readFile(input);
    },
    false
  );
}

function readFile(input) {
  const reader = new FileReader();
  reader.onload = () => {
    const loaded = loadIfc(reader.result);
    scene.add(loaded.MainObject);
  };
  reader.readAsText(input.files[0]);
}

readIfcFile();

var element = document.getElementById('loading');
element.parentNode.removeChild(element);
```

{% endtab %}

{% tab title="main.js" %}

```javascript
export function readIfcFile() {
  const input = document.querySelector('input[type="file"]');
  input.addEventListener(
    'change',
    (e) => {
      readFile(input);
    },
    false
  );
}

function readFile(input) {
    // TODO
}

readIfcFile();
document.getElementById('c').style.display = 'none';
toggleLoader();
```

{% endtab %}
{% endtabs %}

Note that `readFile(input)` has been changed. We will start with an empty function and add in the `FileReader`.

{% code title="example/web-worker/main.js" %}

```javascript
function readFile(input) {
  const reader = new FileReader();
  reader.onload = () => {
      // DO STUFF HERE
    };
  };
  reader.readAsText(input.files[0]);
}
```

{% endcode %}

Til' this point, everything should be pretty easy. Now - let's start implementing the Web Worker.&#x20;

{% code title="example/web-worker/main.js" %}

```javascript
function readFile(input) {
  const reader = new FileReader();
  reader.onload = () => {
    const ifcWorker = new Worker('worker/worker.js');
  };
  reader.readAsText(input.files[0]);
}
```

{% endcode %}

Creating a new worker is super easy. Use [this](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) for more detailed instruction.
