What's the process for creating Shopify CDN asset URLs?

I’m trying to figure out how Shopify makes URLs for assets like images on their CDN. Let’s say I’ve got a picture called ‘company-logo.png’ in my Shopify store.

In a Liquid template, I can get the URL like this:

{{ 'company-logo.png' | asset_url }}

This gives me something like:

http://static.shopify.com/s/files/1/1234/5678/t/3/assets/company-logo.png?987654

I want to make these URLs outside of Shopify for another app I’m working on. I’ve looked at some Shopify code and I can figure out most of the URL parts using the shop ID. But I’m stuck on the ‘/t/3’ bit.

Does anyone know what decides this part of the URL? How can I work it out for my app?

I’ve actually dealt with this issue while building a custom app for Shopify stores. The ‘/t/3’ part you’re seeing is indeed related to the theme version, but it’s a bit trickier than just incrementing numbers. It’s dynamically generated by Shopify and can change unexpectedly.

From my experience, the most reliable way to generate these URLs outside of Shopify is to use their API. You’ll need to make a call to get the current theme ID and then construct the URL using that information. It’s not as straightforward as simply hardcoding a path, but it ensures your URLs will always be up-to-date.

Keep in mind that if you’re building an external app, you’ll need to handle theme updates gracefully. I’d recommend implementing a system to periodically check and update the theme information to keep your asset URLs current.

hey, i’ve used shopify and found that ‘/t/3’ references the theme version. it updates when changes occur. so ya, you likely need the api to fetch the current theme info for accurate urls.