Merge pull request #566 from andrey-git/caching
Fix rules for SW runtime file caching.pull/570/head
commit
798a2bbd34
|
@ -3,8 +3,7 @@ Generate a caching service worker for HA
|
|||
|
||||
Will be called as part of build_frontend.
|
||||
|
||||
Expects home-assistant-polymer repo as submodule of HA repo.
|
||||
Creates a caching service worker based on the CURRENT content of HA repo.
|
||||
Creates a caching service worker based on the built content of the repo in hass_frontend.
|
||||
Output service worker to build/service_worker.js
|
||||
|
||||
TODO:
|
||||
|
@ -70,11 +69,11 @@ gulp.task('gen-service-worker', () => {
|
|||
var url = '/static/panels/ha-panel-' + panel + '-' + hash + '.html';
|
||||
dynamicUrlToDependencies[url] = [fpath];
|
||||
});
|
||||
var fallbackList = '(?!(?:static|api|local|service_worker.js|manifest.json))';
|
||||
|
||||
var options = {
|
||||
navigateFallback: '/',
|
||||
navigateFallbackWhitelist: [RegExp('^(?:' + fallbackList + '.)*$')],
|
||||
navigateFallbackWhitelist:
|
||||
[/^(?:(?!(?:static|api|local|service_worker.js|manifest.json)).)*$/],
|
||||
dynamicUrlToDependencies: dynamicUrlToDependencies,
|
||||
staticFileGlobs: [
|
||||
rootDir + '/icons/favicon.ico',
|
||||
|
@ -86,13 +85,28 @@ gulp.task('gen-service-worker', () => {
|
|||
rootDir + '/fonts/roboto/Roboto-Bold.ttf',
|
||||
rootDir + '/images/card_media_player_bg.png',
|
||||
],
|
||||
runtimeCaching: [{
|
||||
urlPattern: /\/static\/translations\//,
|
||||
handler: 'cacheFirst',
|
||||
}, {
|
||||
urlPattern: RegExp('^[^/]*/' + fallbackList + '.'),
|
||||
handler: 'fastest',
|
||||
}],
|
||||
// Rules are proceeded in order and negative per-domain rules are not supported.
|
||||
runtimeCaching: [
|
||||
{ // Cache static content (including translations) on first access.
|
||||
urlPattern: '/static/*',
|
||||
handler: 'cacheFirst',
|
||||
},
|
||||
{ // Get api (and home-assistant-polymer in dev mode) from network.
|
||||
urlPattern: '/(home-assistant-polymer|api)/*',
|
||||
handler: 'networkOnly',
|
||||
},
|
||||
{ // Get manifest and service worker from network.
|
||||
urlPattern: '/(service_worker.js|manifest.json)',
|
||||
handler: 'networkOnly',
|
||||
},
|
||||
{ // For rest of the files (on Home Assistant domain only) try both cache and network.
|
||||
// This includes the root "/" or "/states" response and user files from "/local".
|
||||
// First access might bring stale data from cache, but a single refresh will bring updated
|
||||
// file.
|
||||
urlPattern: '*',
|
||||
handler: 'fastest',
|
||||
}
|
||||
],
|
||||
stripPrefix: 'hass_frontend',
|
||||
replacePrefix: 'static',
|
||||
verbose: true,
|
||||
|
|
Loading…
Reference in New Issue