Can I reference another asset JS file from an asset JS file in a theme extension using liquid?

Can I reference another asset JS file from an asset JS file in a theme extension using liquid?

Elías
Shopify Partner
19 0 4

In the context of a theme extension... I have multiple js files in my assets folder. Can I reference other files from one file using liquid? For example, if I have an app.js file and a number.js file. Can I do this from my app.js file?

 

For instance

 

app.js

    const script = document.createElement('script');
    script.type = 'text/javascript';
    script.setAttribute('src', "{{ 'number.min.js' | asset_url }}");
    script.onload = function () {
      ...
      ..
      .
    };

 

Replies 2 (2)

PageFly-Noah
Shopify Partner
1317 233 281

This is Noah from PageFly - Shopify Page Builder App

 

Hi @Elías  Yes you can. Then to use the file, you just need to use this code to call that file:

Screen Shot 2024-05-20 at 15.26.51.png

Hope my solution will help you resolve the issue.

Best regards,

Noah | PageFly

Please let me know if it works by giving it a Like or marking it as a solution!


PageFly - #1 Page Builder for Shopify merchants.


All features are available from Free plan. Live Chat Support is available 24/7.

vincent_decaux
Shopify Partner
1 0 0

Hello,

Did you read the question ? the OP is asking how to import a JS file from another JS file.