Skip to content

オフラインでも動くようserviceWorkerを追加#105

Open
na-trium-144 wants to merge 4 commits intomainfrom
offline
Open

オフラインでも動くようserviceWorkerを追加#105
na-trium-144 wants to merge 4 commits intomainfrom
offline

Conversation

@na-trium-144
Copy link
Copy Markdown
Contributor

@na-trium-144 na-trium-144 commented May 2, 2025

  • オフラインでもシ楽バスを開けるようになります
  • 今後htmlやjsファイルを変更するたびにsw.jsの中のバージョン番号を更新する必要がありますが
  • それに加えてこのPRではやってないけどPWA化(extralearn)をすれば完全にオフラインアプリになります (アプリ化するかどうかとオフラインで動くかどうかは無関係)

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented May 2, 2025

Deploying syllabus-frontend with  Cloudflare Pages  Cloudflare Pages

Latest commit: 58f5625
Status: ✅  Deploy successful!
Preview URL: https://6880c555.syllabus-frontend-f3e.pages.dev
Branch Preview URL: https://offline.syllabus-frontend-f3e.pages.dev

View logs

@na-trium-144 na-trium-144 requested a review from Copilot May 2, 2025 02:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds offline support by introducing a new service worker (sw.js) to cache essential files so that the application remains functional offline. Key changes include the implementation of sw.js with file caching logic, updating the DB version comment in script.js to remind developers to update sw.js when relevant files change, and adding service worker registration code in index.html.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
sw.js New service worker file adds offline caching for essential files.
script.js Updated comment regarding DB version now reminds to update sw.js.
index.html Replaced external Material Icons link with a local version and added inline service worker registration code.
Files not reviewed (1)
  • material-icons.css: Language not supported

<link rel="icon" href="resources/favicon-utcode.png" />
<script>
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("/sw.js");
Copy link

Copilot AI May 2, 2025

Choose a reason for hiding this comment

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

Consider adding error handling (e.g., using .catch) to the service worker registration to log any registration failures and assist with debugging offline issues.

Suggested change
navigator.serviceWorker.register("/sw.js");
navigator.serviceWorker.register("/sw.js").catch((error) => {
console.error("Service worker registration failed:", error);
});

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

要るかあ? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants