# How to reference a javascript from within another

**URL:** <https://community.hubspot.com/t/how-to-reference-a-javascript-from-within-another/72743>\
**Category:** CMS Development\
**Tags:** javascript\
**Created:** [January 12, 2023, 10:31am UTC](https://community.hubspot.com/t/how-to-reference-a-javascript-from-within-another/72743 "2023-01-12T10:31:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xyboox](https://avatars.discourse-cdn.com/v4/letter/x/a6a055/32.png) [@xyboox](https://community.hubspot.com/u/xyboox)\
**Post date:** [January 12, 2023, 10:31am UTC](https://community.hubspot.com/t/how-to-reference-a-javascript-from-within-another/72743/1 "2023-01-12T10:31:28Z")

</div>

I am trying to implement some javascript code into our cms webpage template. So I have a javascript file which I use with the require\_js function:

`{{ require_js(get_asset_url("../js/main.bundle.js")) }}`

Somewhere in this main.bundle.js I have code that uses a worker from another file. In standalone code, this is:

`var w = new Worker("./worker.js")`

As is, the worker.js file is not imported when used in HS cms. In console, I get a 404 for the file. I tried:

`var w = new Worker("/hs-fs/${hs_id}/theme_name/js/worker.js")``var w = new Worker("https://our-domain.com/hs-fs/${hs_id}/theme_name/js/worker.js")`

none the above works. Always 404.

Any advise please?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [January 13, 2023, 5:24pm UTC](https://community.hubspot.com/t/how-to-reference-a-javascript-from-within-another/72743/2 "2023-01-13T17:24:57Z")

</div>

Hi, @xyboox 👋 Thank you for the question. Hey, @Indra @miljkovicmisa, do you have any JavaScript wisdom you can share? Or thoughts on how @xyboox might approach this challenge?

Thank you for taking a look! — Jaycee

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [January 15, 2023, 6:12am UTC](https://community.hubspot.com/t/how-to-reference-a-javascript-from-within-another/72743/3 "2023-01-15T06:12:50Z")

</div>

Design manager file URLs update each time you publish them so there’s no set path you can use. You’d either need to:

- Add your file to the page so you can use it’s public URL
- OR upload your file to the file manager and use that URL
- OR set a global variable in a \<script\> in your HTML template so that you can use the get\_asset\_url() HubL function (because HubL isn’t usuable inside javascript files).

```lia-code-sample
<script>
 window.worker = "{{ get_asset_url('relative/file/path/here/file.js') }}";
</script>

```
