Skip to content

Commit

Permalink
add project
Browse files Browse the repository at this point in the history
  • Loading branch information
SiddharthDhirde committed Mar 27, 2024
1 parent 7e6e106 commit 4c48bb8
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
29 changes: 29 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Offline Website</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="content">
<h1>Notice</h1>
<p id="notice-text">Loading...</p>
<p> </p>
</div>
<script src="script.js"></script>
<!-- Register Service Worker -->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/service-worker.js').then(function(registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
console.log('ServiceWorker registration failed: ', err);
});
});
}
</script>
</body>
</html>
7 changes: 7 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Set the localNotice in the localStorage
var localNotice = "This is a Local notice from the server!";
localStorage.setItem('notice', localNotice);

// Update the content of the notice-text paragraph element
var noticeTextElement = document.getElementById('notice-text');
noticeTextElement.textContent = localNotice;
63 changes: 63 additions & 0 deletions service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Service Worker for caching assets
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open('offline-v1').then(function(cache) {
return cache.addAll([
'/',
'/index.html',
'/script.js',
'/style.css'
// Add other assets to cache here if needed
]);
})
);
});

self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});











// // Cache name
// const CACHE_NAME = 'offline-cache-v1';

// // Assets to cache
// const assetsToCache = [
// '/',
// '/index.html',
// '/style.css',
// '/script.js'
// // Add more assets as needed
// ];

// // Install event
// self.addEventListener('install', event => {
// event.waitUntil(
// caches.open(CACHE_NAME)
// .then(cache => cache.addAll(assetsToCache))
// );
// });

// // Fetch event
// self.addEventListener('fetch', event => {
// event.respondWith(
// caches.match(event.request)
// .then(response => response || fetch(event.request))
// .catch(() => {
// // Handle fetch errors
// })
// );
// });
9 changes: 9 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
body {
background-color: black;
color: white;
font-family: Arial, sans-serif;
}
.content {
text-align: center;
margin-top: 50px;
}

0 comments on commit 4c48bb8

Please sign in to comment.