I am trying to include a JavaScript file (named StoreLocator.js) from my Shopify assets by using the URL filters as explained in the Shopify documentation (see https://shopify.dev/api/liquid/filters/url-filters).
First of all, I uploaded the JavaScript file to the assets folder. I noticed during debugging that the uploaded JavaScript file is accessible under the following URL:
https://cdn.shopify.com/s/files/1/0551/8009/9636/t/6/assets/StoreLocator.js
I was able to debug this, because I used the same JavaScript file and the same URL filter in a previous project and it worked just fine. Therefore I could see, that Shopify uses this URL to load the JavaScript file.
However, by using the following URL-filter in the new project.
{{ 'StoreLocator.js' | asset_url | script_tag }}
it generates the following URL which is incorrect (note the part /t/6 vs /t9.
https://cdn.shopify.com/s/files/1/0551/8009/9636/t/9/assets/StoreLocator.js
Unfortunately I could not find any documentation about the URLs that the Shopify CDN generates. In the present case it would be interesting to know why the URL changed from /t/6 to /t9.
Can someone explain why the URL filter does not point to the correct URL?
Try this code it will work:-
Make sure your StoreLocator.js file is present in Assets folder
<script src="{{ 'StoreLocator.js' | asset_url }}" ></script>
After using this you have to check this url in 'view page source' and click this url and check url code in browser and in any code editor