Shopify 资产未加载

发布于 2025-01-14 19:21:44 字数 1106 浏览 2 评论 0原文

我尝试使用 URL 过滤器从我的 Shopify 资产中包含一个 JavaScript 文件(名为 StoreLocator.js),如 Shopify 文档中所述(请参阅 https://shopify.dev/api/liquid/filters/url-filters)。

首先,我将 JavaScript 文件上传到 asset 文件夹。我在调试过程中注意到,可以通过以下 URL 访问上传的 JavaScript 文件:

https://cdn.shopify.com/s/files/1/0551/8009/9636/t/6/assets/StoreLocator.js

我能够调试这个,因为我使用了相同的JavaScript 文件和之前项目中的相同 URL 过滤器,效果很好。因此我可以看到,Shopify 使用此 URL 来加载 JavaScript 文件。

但是,通过在新项目中使用以下 URL 过滤器。

{{ 'StoreLocator.js' | asset_url | script_tag }}

它生成以下不正确的 URL(请注意 /t/6/t9 部分。

https://cdn.shopify.com/s/files/1/0551/8009/9636/t/9/assets/StoreLocator.js

不幸的是,我找不到任何有关 URL 的文档 会很有趣。

在本例中,了解 URL 从 /t/6 更改为 /t9 的原因 观点到正确的网址?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝影如岚 2025-01-21 19:21:44

尝试此代码,它会起作用: -

确保您的 StoreLocator.js 文件存在于 Assets 文件夹中

<script  src="{{ 'StoreLocator.js' | asset_url }}" ></script>

使用此后,您必须在“查看页面源代码”中检查此 url,然后单击此 url 并在浏览器和任何代码编辑器中检查 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文