4

I went to GitHub issues to raise a support ticket but thought of asking the question first to avoid noise.

This is what the docs says-

Omit the version completely or use "latest" to load the latest one (not recommended for production usage):

/npm/jquery@latest/dist/jquery.min.js
/npm/jquery/dist/jquery.min.js

According to the doc, either we can latest or omit it completely to load the latest version. But I'm seeing a difference-

With latest added (URL 1 - U1)

Example- https://cdn.jsdelivr.net/npm/@letscooee/web-sdk@latest/dist/sdk.min.js

It loads the last released version that is cached for 24 hours. That means if we release v2 & v3 within 24 hours, the above URL will still show v1.

The caching period is 1 week.

Without latest (URL 2 - U2)

Example- https://cdn.jsdelivr.net/npm/@letscooee/web-sdk/dist/sdk.min.js

While we omit the latest completely, this loads the latest release immediately i.e. v3 and the caching period is also 1 week.

I have requested for the purge API as per their docs but I believe this behaviour is not aligning with their docs.

Tried to Google the cause and read their docs 3 times. Am I missing something?

Edit 1

After reading Martin's answer, I did the following-

(To view the images, open them in new tab & remove t before .png)

Step Taken @ Time U1 U2
Purge Cache 12:39:00 UTC Purged Purged
See Age Header @ 12:40 UTC 0 0
See Date Header @ 12:40 UTC Sun, 12 Sep 2021 12:40:25 GMT Sun, 12 Sep 2021 12:40:31 GMT
Headers 12:41:00 UTC enter image description here enter image description here
Result 12:41:00 UTC Points to latest release 0.0.3 Points to latest release 0.0.3
Publish new NPM release 0.0.4 12:48:00 UTC
Refresh both the URLs 12:49:00 UTC Shows old release 0.0.3 Shows latest release 0.0.4

The last step shows that I was wrong here. This is working as expected (i.e. showing 0.0.3 only) as per the docs

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121

2 Answers2

2

The caching time is the same in both cases - 12 hours at the CDN level and 7 days in the browser: cache-control: public, max-age=604800, s-maxage=43200

That doesn't necessarily mean both URLs will always return the same content because both the CDN and your browser calculate the expiration for each URL independently, based on when it was first retrieved, so the CDN may serve different versions for up to 12 hours after the release.

Martin Kolárik
  • 721
  • 5
  • 7
  • Thanks for taking the time to respond. While I am totally in sync with the explanation you gave, I still see a difference. So I'm putting my question & comments based on the Age response header. If I look at the Age header of both the URLs, one is in the Proxy cache for around 1.5 hours and the other is in cache for around 45 minutes. So if I publish a new update (immediately now), both should not get updated for about ~10 hours. Am I right? – Shashank Agrawal Sep 12 '21 at 12:30
  • Most of the time probably yes, both won't be updated for about 10 hours. But `max-age` really means just "max", not "exact" so there are cases when the CDNs may be updated faster. – Martin Kolárik Sep 12 '21 at 12:50
  • Got it, Martin. I did extensive testing step-by-step to show you the difference but I was wrong and the behaviour is correct as expected (as per the doc). Thanks again a ton! – Shashank Agrawal Sep 12 '21 at 12:59
  • By the way, I updated my steps in the question. Just for you to see. No further action is required. – Shashank Agrawal Sep 12 '21 at 12:59
-1

Seems to me both the links point to the same sdk URL. As per how cdns work would be to mention the version of the sdk for example:

<script src="https://unpkg.com/three@0.126.0/examples/js/loaders/GLTFLoader.js"></script>

or as per below which will always point to the latest version of the sdk:

<script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/loaders/GLTFLoader.js"></script>
Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
Ambriel.AR
  • 11
  • 3