# How to get asset path in javascript?

**URL:** <https://community.hubspot.com/t/how-to-get-asset-path-in-javascript/34035>\
**Category:** CMS Development\
**Tags:** professional\
**Created:** [March 17, 2021, 3:01pm UTC](https://community.hubspot.com/t/how-to-get-asset-path-in-javascript/34035 "2021-03-17T15:01:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jinwoooh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jinwoooh/32/43872_2.png) [@jinwoooh](https://community.hubspot.com/u/jinwoooh)\
**Post date:** [March 17, 2021, 3:01pm UTC](https://community.hubspot.com/t/how-to-get-asset-path-in-javascript/34035/1 "2021-03-17T15:01:14Z")

</div>

I need to implement animation on our website, and we are trying to use 3rd party library.

The problem is that I don’t know how I can get the asset file path from a javascript file.

I know that get\_asset\_url works on hubl, but it doesn’t work on a javascript file.

Any idea how to get an asset path from js file?

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [March 17, 2021, 7:31pm UTC](https://community.hubspot.com/t/how-to-get-asset-path-in-javascript/34035/2 "2021-03-17T19:31:38Z")

</div>

Hi @jinwoooh,

if you want to use an external JS file in a module/template I recommend you to use the [require\_js function](https://developers.hubspot.com/docs/cms/hubl/functions#require-js).

How to get the asset path of your js file:

- copy/paste the URL(if it has one) into the require\_js function and place this snippet into the header/footer (where it should be placed) // most likely the easiest solution
- create a new js file in the design-manager and paste the whole js code into it - save it - right-click on the file and select “copy path” - place it into the require\_js function // great if you wnat to modify the file; HubSpot will automaticly minify the file if it’s not minified
- create a new js file locally and upload it to the file-manager(not design-manager) copy the path and place it the require\_js function // it’s okay but not really recommended since HubSpot won’t minify it
- There is another option but since this is quite “the worst way possible” I won’t tell you 😁

hope this helps,

best,

Anton

---

<div class="post-metadata">

**Author:** ![jinwoooh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jinwoooh/32/43872_2.png) [@jinwoooh](https://community.hubspot.com/u/jinwoooh)\
**Post date:** [March 17, 2021, 7:39pm UTC](https://community.hubspot.com/t/how-to-get-asset-path-in-javascript/34035/3 "2021-03-17T19:39:43Z")

</div>

Hi @Anton ,

I get that we can get a js file path, but I want to get a json file path that I uploaded to module/template from a js file.

My js code looks like this,

var st = bodymovin.loadAnimation({  
container: document.getElementById(‘st’),  
renderer: ‘svg’,  
loop: true,  
autoplay: true,  
// animation file path  
path: ‘JSON FILE PATH HERE!!!’  
})

and I don’t know what’s the best way to get json file path from here.

Thanks,

Jinwoo

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [September 20, 2022, 2:45pm UTC](https://community.hubspot.com/t/how-to-get-asset-path-in-javascript/34035/4 "2022-09-20T14:45:35Z")

</div>

Hi @jinwoooh,

if get\_asset\_url doesn’t work:  
Try to write it like this:

```lia-code-sample
{{get_asset_url('../../boilerplate/js/main.js')}}

```

basically replacing the first folder with “..”. This can help sometimes.

Another possible way could be to upload your JSON file to the file manager and get the URL from there.

best,

Anton

---

<div class="post-metadata">

**Author:** ![MEl-ghorfi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mel-ghorfi/32/196389_2.png) [@MEl-ghorfi](https://community.hubspot.com/u/MEl-ghorfi)\
**Post date:** [September 15, 2022, 11:45pm UTC](https://community.hubspot.com/t/how-to-get-asset-path-in-javascript/34035/5 "2022-09-15T23:45:12Z")

</div>

I had the same issue, check it out here: [https://medium.com/@elghorfi.med/get-shopify-asset-url-in-javascript-33dd5c6ff1d7](https://medium.com/@elghorfi.med/get-shopify-asset-url-in-javascript-33dd5c6ff1d7)
