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

feat: enable cache for index.js using Last-Modified header validation using Service Worker #118

Closed
wants to merge 1 commit into from

Conversation

AhyoungRyu
Copy link
Collaborator

@AhyoungRyu AhyoungRyu commented Mar 13, 2024

Aims to enable aichatbot.sendbird.com/index.js caching strategy by incorporating Last-Modified header validation. This update ensures that our service worker efficiently manages the cached assets, improving the user experience by leveraging up-to-date content and reducing unnecessary network requests.

How it works?

graph TD;
    A[Check for Cached Response] -->|Exists| B(Fetch Latest Response from Server);
    A -->|Does Not Exist| F(Fetch New Response from Network);
    B --> C{Compare Last-Modified Headers};
    C -->|Server Newer| D[Update Cache with New Response];
    C -->|Same as Cache or Invalid| E[Return Cached Response];
    D --> G[Return New Response to Client];
    E --> G;
    F --> H[Store New Response in Cache];
    H --> I[Return New Response to Client];
Loading

Possible benefits:

  • Reduces bandwidth usage by avoiding unnecessary network requests.
  • Ensures users have access to the most up-to-date content without compromising load times.
  • Enhances offline capabilities by maintaining a fresh cache.

@bang9
Copy link
Contributor

bang9 commented Mar 13, 2024

일단 제 3자가 배포한 service-worker 를 cross-origin 에서 불러와서 사이트에 이식이 가능한지 먼저 살펴보아야 할 것 같은데요
좀 찾아보니 https://developer.chrome.com/blog/foreign-fetch 요런 실험적 기능으로 다룬 아티클이 있었는데
w3c/ServiceWorker#1188 요기서 스펙에서 제외되었다고 하네요

@bang9
Copy link
Contributor

bang9 commented Mar 13, 2024

좀 더 읽어보니 cross-origin 에서 install 하는게 아니라 foreign fetch 라는 기능이 제거되었다는거네요
https://developer.chrome.com/blog/foreign-fetch#registering_your_service_worker 요쪽에서 제안하는 방식은 헤더에 심어서 등록하는거네요 😮 일단 아티클이 좀 된거같아서, 요게 동작하는지 먼저 검증하면 좋을 것 같습니다!

@bang9
Copy link
Contributor

bang9 commented Mar 13, 2024

그리고 위의 방식으로 설치하는게 가능하다면, 사이트에 몰래 스크립트를 심는거나 다름이 없어 보이는데요..🤔 (동작 방식 자체가)
그래서 보안상 문제등으로 인해 API 제약등도 있을 것 같은데, 요 부분도 확인해봐야 할 것 같아요

@AhyoungRyu
Copy link
Collaborator Author

@bang9 의견 감사했습니다~! #119 로 대체하게 되었으니 요건 닫을게요 :)

@AhyoungRyu AhyoungRyu closed this Mar 14, 2024
@AhyoungRyu AhyoungRyu deleted the feat/apply-sw branch March 14, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants