Skip to content

Commit

Permalink
[FEATURE] Add service worker (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszuznanski authored Oct 26, 2019
1 parent b1fec2c commit f8d84c4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,28 @@ manifest {
10 {
userFunc = FriendsOfTYPO3\PwaManifest\Service\ConfigurationService->provideConfiguration
}
}
}

##############
#### PAGE ####
##############
page = PAGE
page {
headerData {
198765 = TEXT
198765.value = <link rel="manifest" href="/?type=835">
}
jsFooterInline {
198765 = COA
198765 {
10 = TEXT
10.value (
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/typo3conf/ext/pwa_manifest/Public/Javascript/sw.js');
});
}
)
}
}
}
32 changes: 32 additions & 0 deletions Public/Javascript/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
importScripts('https://cdn.jsdelivr.net/npm/[email protected]/workbox/workbox-sw.js')

// --------------------------------------------------
// Configure
// --------------------------------------------------

// Set workbox config
workbox.setConfig({
"debug": false
})

// Start controlling any existing clients as soon as it activates
workbox.core.clientsClaim()

// Skip over the SW waiting lifecycle stage
workbox.core.skipWaiting()

workbox.precaching.cleanupOutdatedCaches()

// --------------------------------------------------
// Precaches
// --------------------------------------------------

// Precache assets

// --------------------------------------------------
// Runtime Caching
// --------------------------------------------------

// Register route handlers for runtimeCaching
workbox.routing.registerRoute(new RegExp('/fileadmin/.*'), new workbox.strategies.NetworkFirst ({"cacheName":"assets-cache","maxAgeSeconds":86400}), 'GET')
workbox.routing.registerRoute(new RegExp('/'), new workbox.strategies.NetworkFirst ({}), 'GET')

0 comments on commit f8d84c4

Please sign in to comment.