浏览代码

caching

master
Flo Smilari 4 年前
父节点
当前提交
a92543040c
共有 4 个文件被更改,包括 74 次插入9 次删除
  1. 6
    0
      CaritasPWA.csproj
  2. 1
    0
      CaritasPWA.csproj.user
  3. 6
    6
      Properties/launchSettings.json
  4. 61
    3
      wwwroot/service-worker.js

+ 6
- 0
CaritasPWA.csproj 查看文件

@@ -11,6 +11,12 @@
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
<OutputType>Exe</OutputType>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>

+ 1
- 0
CaritasPWA.csproj.user 查看文件

@@ -5,6 +5,7 @@
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>CaritasPWA</ActiveDebugProfile>
<NameOfLastUsedPublishProfile>FolderProfile</NameOfLastUsedPublishProfile>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Update="Shared\ResourceFiles\Resources.it.resx">

+ 6
- 6
Properties/launchSettings.json 查看文件

@@ -11,19 +11,19 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
},
"CaritasPWA": {
"commandName": "Project",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
}
}
}
}

+ 61
- 3
wwwroot/service-worker.js 查看文件

@@ -2,15 +2,73 @@
// This is because caching would make development more difficult (changes would not
// be reflected on the first load after each change).
const staticCacheName = 'site-static-v1';
const assets = [
'/',
'/index.html',
'/account',
'/account/Found',
'/account/Missing',
'/info',
'/caritas_services',
'/lost_found',
'/keydata',
'/keydata/Found',
'/keydata/Missing',
'/conclusion_found',
'/conclusion_missing',
'/doneimage',
'css/app.css',
'_content/BlazorColorPicker/colorpicker.css',
'_content/MatBlazor/dist/matBlazor.css',
'css/united/bootstrap.min.css',
'css/united/_bootswatch.min.css',
'css/united/_variables.min.css',
'_content/BlazorAnimate/blazorAnimateInterop.js',
'_content/MatBlazor/dist/matBlazor.js',
'_content/BlazorColorPicker/colorpicker.js',
'images/batch_found.png',
'images/batch_fundvelo.png',
'images/batch_kulturlegi.png',
'images/batch_markt.png',
'images/batch_missing.png',
'images/caritas_logo.png',
'images/integrate_logo.png',
'images/done.png',
'images/icon_camera.png',
'images/icon_driveupload.png',
'images/icon_location.png'
];
// install event
self.addEventListener('install', evt => {
console.log("Service-Worker has been installed.");
evt.waitUntil(
caches.open(staticCacheName).then(cache => {
console.log('caching app assets');
cache.addAll(assets);
})
);
});
// activate event
self.addEventListener('activate', evt => {
console.log("Service-Worker has been activated.");
//console.log("Service-Worker has been activated.");
evt.waitUntil(
caches.keys().then(keys => {
return Promise.all(keys
.filter(key => key !== staticCacheName)
.map(key => caches.delete())
)
})
);
});
self.addEventListener('fetch', () => { });
self.addEventListener('fetch', evt => {
evt.respondWith(
caches.match(evt.request).then(cacheRes => {
return cacheRes || fetch(evt.request);
})
);
});

正在加载...
取消
保存