Skip to content

Commit

Permalink
local testing causing a conflict in production
Browse files Browse the repository at this point in the history
  • Loading branch information
mistermatt1337 committed Apr 15, 2024
1 parent c9dfa38 commit ed5c49c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# .gitignore

# Ignore all dot files
.*
#.*

# But not these ones
!.gitignore
Expand Down
7 changes: 4 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ <h1>Like what we're doing? </h1><p>Here are some ways you can show your apprecia
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/RSI-Waves2Epochs/sw.js', {scope: '/RSI-Waves2Epochs/'}).then(function(registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope); // Successful registration
const scope = location.hostname === 'sc-open.github.io' ? '/RSI-Waves2Epochs/' : '/';
navigator.serviceWorker.register('sw.js', {scope: scope}).then(function(registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
console.log('ServiceWorker registration failed: ', err); // Failed registration
console.log('ServiceWorker registration failed: ', err);
});
});
}
Expand Down
7 changes: 2 additions & 5 deletions sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ self.addEventListener('install', event => {
event.waitUntil((async () => {
try {
// Fetch the manifest file
const response = await fetch(new URL('/RSI-Waves2Epochs/manifest.webmanifest'));
const response = await fetch('/RSI-Waves2Epochs/manifest.webmanifest');
const manifest = await response.json();

const cache = await caches.open(CACHE_NAME);
await cache.addAll([
'/RSI-Waves2Epochs/',
OFFLINE_URL,
'/RSI-Waves2Epochs/index.html',
'/RSI-Waves2Epochs/js/content.js',
'/RSI-Waves2Epochs/css/styles.css',
'/RSI-Waves2Epochs/css/footer.css'
Expand All @@ -28,20 +29,16 @@ self.addEventListener('fetch', event => {
try {
// Try to get the response from the network
const fetchResponse = await fetch(event.request);

// If the fetch was successful, put the new resource in the cache
const cache = await caches.open(CACHE_NAME);
const cachePut = cache.put(event.request, fetchResponse.clone());

// Use event.waitUntil() to wait for the caching operation to complete
event.waitUntil(cachePut);

return fetchResponse;
} catch (e) {
// The network request failed, try to get the result from the cache
const cache = await caches.open(CACHE_NAME);
const cachedResponse = await cache.match(event.request);

if (cachedResponse) {
// Return the cached response if available
return cachedResponse;
Expand Down

0 comments on commit ed5c49c

Please sign in to comment.