Make / and other fallback paths runtime cachable instead of pre-cached.

This commit is contained in:
andrey-git 2017-11-02 00:23:25 +02:00
parent 979a22f311
commit 085f46b753

View File

@ -26,13 +26,7 @@ const DEV = !!JSON.parse(process.env.BUILD_DEV || 'true');
var rootDir = 'hass_frontend'; var rootDir = 'hass_frontend';
var panelDir = path.resolve(rootDir, 'panels'); var panelDir = path.resolve(rootDir, 'panels');
var dynamicUrlToDependencies = { var dynamicUrlToDependencies = {};
'/': [
rootDir + '/frontend.html',
rootDir + '/core.js',
rootDir + '/compatibility.js',
],
};
var staticFingerprinted = [ var staticFingerprinted = [
'frontend.html', 'frontend.html',
@ -76,10 +70,11 @@ gulp.task('gen-service-worker', () => {
var url = '/static/panels/ha-panel-' + panel + '-' + hash + '.html'; var url = '/static/panels/ha-panel-' + panel + '-' + hash + '.html';
dynamicUrlToDependencies[url] = [fpath]; dynamicUrlToDependencies[url] = [fpath];
}); });
var fallbackList = '(?!(?:static|api|local|service_worker.js|manifest.json))';
var options = { var options = {
navigateFallback: '/', navigateFallback: '/',
navigateFallbackWhitelist: [/^((?!(static|api|local|service_worker.js|manifest.json)).)*$/], navigateFallbackWhitelist: [RegExp('^(?:' + fallbackList + '.)*$'],
dynamicUrlToDependencies: dynamicUrlToDependencies, dynamicUrlToDependencies: dynamicUrlToDependencies,
staticFileGlobs: [ staticFileGlobs: [
rootDir + '/icons/favicon.ico', rootDir + '/icons/favicon.ico',
@ -94,6 +89,9 @@ gulp.task('gen-service-worker', () => {
runtimeCaching: [{ runtimeCaching: [{
urlPattern: /\/static\/translations\//, urlPattern: /\/static\/translations\//,
handler: 'cacheFirst', handler: 'cacheFirst',
}, {
urlPattern: RegExp('^[^/]*/' + fallbackList + '.'),
handler: 'fastest',
}], }],
stripPrefix: 'hass_frontend', stripPrefix: 'hass_frontend',
replacePrefix: 'static', replacePrefix: 'static',