Easy way to use assets by name in JS? What is ?v= '#'

I am trying to upload multiple assets and address them by name like cheese.mp3 and mg-alert.mp3 :

and

The start of the URL is the same https://cdn.glitch.com/f1d75616-3034-412e-99b5-a41604b11078%2F

and then the name is what I expect, but then it has this random number ?v=1566171684860.

The URL breaks and grabs the wrong song if I take the ?v=1566171684860 ending off: https://cdn.glitch.com/f1d75616-3034-412e-99b5-a41604b11078%2Fmg-alert.mp3

Question: Is there an easy way I can use my assets by name in Javascript without needing to find and record the ?v= value for every asset?

The ?v=longnumber is a parameter to the url, effectively giving the asset a version number.

If you leave it out, the asset will load okay, but will load whichever version is cached by the browser, and possibly cached by the cdn, to make the website seem faster to the user.

So you really do need it included to make sure the correct version (latest) of the asset gets loaded, but only if you update the asset.

2 Likes

It definitely seems to be cached by the CDN. I change browsers and it doesn’t make a difference. Version makes perfect sense for “v”, thanks!

I wish there was some way to clear the CDN cache. Maybe if I don’t screw up and change the files it will be ok.

You may be able to refer to the file with a shorter version string,

apple.png?v=2

and the cdn says to itself “I haven’t seen that before, I’ll go fetch it”.

I haven’t tried it on Glitch, but works elsewhere.