Hosting javascript file on store domain instead of CDN

Hi all,

So I’m wondering if shopify supports any way of loading a javascript file in on a store site on the same domain as the store and not on the CDN.

This would allow for the use of webworkers and creating Progressive web apps using shopify’s theme’s instead of forcing to create a separate app and using the headless api’s.

2 Likes

All files, go on the CDN. But you could try adding it to your asset folder and calling it with:

{{ 'file_name.extensions' | asset_url | script_tag }}

Hi,

Thanks for your reply.

Putting a (custom) script in assets and refering it to with the asset_url filter will neatly make a cdn url for it. Which is of course usually what you want.

However https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API Web workers force to load a script file from the same origin as the dom document. If the script is hosted by a cdn, aka not the same origin, then unfortunately it wont work. Which is why I’m trying to find a way to host this js file on the shop store domain.

Have you tried programming the code in direct into the template with

Web workers are created using new Worker([url to some file]) and that url needs to adhere to same origin policy. It doesnt matter if I call it in a script loaded into the document or in a script tag in the document, the file I’m trying to get needs to be on the same origin as the store, which you indicate is not possible. And that might be true since I’ve found no documentation on how to host assets anywhere else but on the shopify cdn.

Ya. The CDN is used for everything, even Shopify’s core files. So sadly I do not think it would be possible.

1 Like

I really need a solution and keep getting blocked to work with the api as its limited to 250 calls for each fetch and having this loop through my products crashes my UI so I will need to create a new thread to run this fetch loop, I can do that with worker.