Skip to content

Commit

Permalink
fix more browser warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
phughesmcr committed Sep 2, 2024
1 parent 3854629 commit 72f4619
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 3 deletions.
17 changes: 14 additions & 3 deletions routes/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type PageProps } from "$fresh/server.ts";
import { asset } from "$fresh/runtime.ts";
import { type PageProps } from "$fresh/server.ts";

const JSONLD = {
"@context": "http://www.schema.org",
Expand Down Expand Up @@ -78,12 +78,23 @@ export default function App({ Component }: PageProps) {
/>

<link rel="stylesheet" href={asset("/styles.css")} />

<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: `${JSONLD}` }}
dangerouslySetInnerHTML={{ __html: `${JSON.stringify(JSONLD)}` }}
>
</script>
<link rel="stylesheet" href="/styles.css" />
{/* <script dangerouslySetInnerHTML={{__html: `
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js').then(function(registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
console.log('ServiceWorker registration failed: ', err);
});
});
}
`}}></script> */}
</head>
<body>
<Component />
Expand Down
34 changes: 34 additions & 0 deletions static/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "DebateThing.com",
"short_name": "DebateThing",
"description": "An experimental tool for creating simulated debates using AI",
"icons": [
{
"src": "/favicon-16x16.png",
"sizes": "16x16",
"type": "image/png"
},
{
"src": "/favicon-32x32.png",
"sizes": "32x32",
"type": "image/png"
},
{
"src": "/apple-touch-icon.png",
"sizes": "180x180",
"type": "image/png"
},
{
"src": "/img/512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#1881F2",
"background_color": "#ffffff",
"display": "standalone",
"orientation": "any",
"start_url": "/",
"scope": "/",
"lang": "en-US"
}
9 changes: 9 additions & 0 deletions static/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.debatething.com/</loc>
<lastmod>2024-09-02</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
</urlset>
81 changes: 81 additions & 0 deletions static/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const CACHE_NAME = 'debatething-cache-v1';
const urlsToCache = [
'/',
'/styles.css',
'/favicon.ico',
'/favicon-16x16.png',
'/favicon-32x32.png',
'/apple-touch-icon.png',
'/safari-pinned-tab.svg',
'/site.webmanifest',
];

self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME)
.then((cache) => {
return Promise.all(
urlsToCache.map(url => {
return fetch(url)
.then(response => {
if (!response.ok) {
throw new Error(`Failed to fetch ${url}`);
}
return cache.put(url, response);
})
.catch(error => {
console.error('Caching failed for', url, error);
return Promise.resolve();
});
})
);
})
);
});

self.addEventListener('fetch', (event) => {
// Check if the request is a POST request
if (event.request.method === 'POST') {
// For POST requests, bypass the cache and fetch from the network
event.respondWith(fetch(event.request));
return;
}

// For non-POST requests, use the cache-first strategy
event.respondWith(
caches.match(event.request)
.then((response) => {
if (response) {
return response;
}
return fetch(event.request).then(
(response) => {
if (!response || response.status !== 200 || response.type !== 'basic') {
return response;
}
const responseToCache = response.clone();
caches.open(CACHE_NAME)
.then((cache) => {
cache.put(event.request, responseToCache);
});
return response;
}
);
})
);
});

self.addEventListener('activate', (event) => {
const cacheWhitelist = [CACHE_NAME];
event.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames.map((cacheName) => {
if (cacheWhitelist.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
})
);
})
);
});

0 comments on commit 72f4619

Please sign in to comment.