Skip to content

Commit

Permalink
Update to 2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
denysdesign committed Mar 5, 2024
1 parent 5eda87d commit 5f0f9ac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 49 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
basedir=".">

<property name="VERSION"
value="2.0.1" />
value="2.0.2" />
<property name="JOOMLA"
value="4.0" />

Expand Down
4 changes: 3 additions & 1 deletion packages/plg_system_jupwa/libraries/src/Helpers/META.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ public static function manifest(): void
if(file_exists(JPATH_SITE . '/' . $file))
{
$href = Uri::root() . $file;
$doc->addHeadLink($href, 'manifest');
$doc->addHeadLink($href, 'manifest', 'rel', [
'crossorigin' => 'use-credentials'
]);
}
}

Expand Down
55 changes: 8 additions & 47 deletions packages/plg_system_jupwa/tmpl/sw.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,62 +29,21 @@

const offlineFallbackPage = "/offline.php";

const HOSTNAME_WHITELIST = [
self.location.hostname,
'fonts.gstatic.com',
'fonts.googleapis.com'
];

self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});

// Offline
const getFixedUrl = (req) => {
let now = Date.now(),
url = new URL(req.url);

url.protocol = self.location.protocol;

if (url.hostname === self.location.hostname) {
url.search += (url.search ? '&' : '?') + 'cache-bust=' + now;
}

return url.href;
}

self.addEventListener('activate', event => {
event.waitUntil(self.clients.claim());
})

self.addEventListener('fetch', event => {
if (HOSTNAME_WHITELIST.indexOf(new URL(event.request.url).hostname) > -1) {
const cached = caches.match(event.request),
fixedUrl = getFixedUrl(event.request),
fetched = fetch(fixedUrl, { cache: 'no-store' }),
fetchedCopy = fetched.then(resp => resp.clone());

event.respondWith(
Promise.race([fetched.catch(_ => cached), cached])
.then(resp => resp || fetched)
);

event.waitUntil(
Promise.all([fetchedCopy, caches.open( CACHE )])
.then(([response, cache]) => response.ok && cache.put(event.request, response))
);
}
self.addEventListener('install', async (event) => {
event.waitUntil(
caches.open(CACHE)
.then((cache) => cache.add(offlineFallbackPage))
);
});

setCatchHandler(async ({event}) => {
if (event.request.destination === 'document') {
return new matchPrecache(offlineFallbackPage);
}

return new Response.error();
});
self.addEventListener('activate', () => self.clients.claim());

// Preload
if (workbox.navigationPreload.isSupported()) {
Expand Down Expand Up @@ -151,10 +110,12 @@
return preloadResp;
}
const networkResp = await fetch(event.request);

return networkResp;
} catch (error) {
const cache = await caches.open(CACHE);
const cachedResp = await cache.match(offlineFallbackPage);

return cachedResp;
}
})());
Expand Down

0 comments on commit 5f0f9ac

Please sign in to comment.