How to Force Reload / Clear Cache of .js.liquid file Assets Folder

Tourist
4 0 1

We have a javascript asset saved in the Assets folder of storefronts that have installed our app. It appears this file is heavily cached. Is there a way to force a store to clear the cache immediately and reload the javascript file we've specified?

 

If not, is there some reasonable expectation for how long before these files are reloaded by Shopify's CDN?

 

0 Likes

Following. 

Want to customize or make changes to a theme? Hire me.
If my answer was helpful please Like and Accept Solution.
Email: oscardiazserrat@gmail.com
Behance: behance.net/starseedscreative
0 Likes
Shopify Partner
2 0 0

Following too.

0 Likes
Shopify Expert
2000 82 1452

Assets are loaded (unless yo've hardcoded things in directly) with the versioning id appended. eg:
https://cdn.shopify.com/s/files/1/1198/0996/t/2/assets/theme.js?212

 

What's the issue with cache that you are seeing that the above doesn't solve?

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Excursionist
21 1 6

I have the same issue: when I edit the {% stylesheet %} in a section file, the change isn't immediately visible on the front-end: the original style is still in place.

 

The workaround I've found is: if you make any change to the section outside of a stylesheet/javascript directive (ie, the actual HTML), it seems to force the cache refresh (the version number changes: in view-source, you'll see "compiled_assets/styles.css?192" < this number increments by 1 or more )

 

That said, I've also seen cases where it does refresh on its own.

0 Likes
New Member
2 0 0

I'm experiencing the same issue too. Seems to be happening with .js.liquid files.

0 Likes
Tourist
6 1 3

Seems like  script_tag is not working correctly with cache busting
So instead of:

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

Use this:

<script src={{ 'shop.js' | asset_url }}" type="text/javascript"></script>

 

0 Likes
New Member
1 0 1

I found that if you put the reference to your JavaScript or CSS file in a Snippet instead of directly into the theme.liquid file, then it doesn't get cached in the CDN.

 

theme.liquid

Contains reference to the snippet between the <head> tag. For example, using a snippet named 'head':

 

<head>

    {% include 'head' %}

</head>

 

head.liquid

{% capture theme_styles %}
   {{ 'custom.css' | asset_url | stylesheet_tag }}
{% endcapture %}
 
{% capture theme_scripts %}
   {{ 'custom.js'  | asset_url | script_tag     }}
{% endcapture %}
1 Like