Search code examples
npmhttp-cachingjsdelivr

Difference in JSDelivr URL with & without "latest"


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


Solution

  • 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.