Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/autoupdating cdn downtime #2467

Merged
merged 4 commits into from
Dec 16, 2024
Merged

Conversation

mimi-imtbl
Copy link
Contributor

@mimi-imtbl mimi-imtbl commented Dec 16, 2024

Hi👋, please prefix this PR's title with:

  • breaking-change: if you have introduced modification that necessitates immediate adjustments by this SDK's users to their applications, clients, or integrations to avert disruptions to existing features or functionalities.
  • feat:, fix:, refactor:, docs:, or chore:.

Summary

To resolve issues with CDN and browser caching when loading the @latest version of the package, we have previously introduced a mechanism to query the NPM registry for a specific version.

This approach ensures that apps hosting the widget load a precise version of the package, such as:
https://cdn.jsdelivr.net/npm/@imtbl/[email protected]/dist/browser/checkout/widgets-esm.js.

While this resolves caching issues, it introduces a new issue: CDN propagation delays. It typically takes 5–10 minutes for the new version to become fully available on the CDN. During this period, if a user accesses the app, the widget's files for the specific the specific latest version may not yet be accessible.

This PR adds a last_updated.json file containing a timestamp recorded just before the package is published to NPM. The widget:

  1. Queries the NPM registry for the latest specific version.
  2. Checks the last_updated.json file on the CDN.
  3. If less than 20 mins have passed since the release timestamp, it falls back to the @latest version (https://cdn.jsdelivr.net/npm/@imtbl/sdk@latest/dist/browser/checkout/widgets-esm.js).
  4. If more than 20 mins have passed, it loads the specific latest version.

This ensures users have access to the latest version of widgets while avoiding the downtime due to CDN propagation delays. The experience remains seamless, requiring no user intervention (e.g. no need for hard browser reloads to clear browser cache).

@mimi-imtbl mimi-imtbl requested review from a team as code owners December 16, 2024 02:06
Copy link

nx-cloud bot commented Dec 16, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 26cb5e1. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

Copy link
Contributor

@alejoloaiza alejoloaiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mimi-imtbl mimi-imtbl added this pull request to the merge queue Dec 16, 2024
Merged via the queue into main with commit 13de51f Dec 16, 2024
8 checks passed
@mimi-imtbl mimi-imtbl deleted the fix/autoupdating-cdn-downtime branch December 16, 2024 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants