Kaynağa Gözat

service-worker strategy changed to network first

master
Flo Smilari 4 yıl önce
ebeveyn
işleme
4e3a9587c8

+ 1
- 1
Pages/CaritasServiceFundVeloFoundKeyDataPage.razor.cs Dosyayı Görüntüle

@@ -80,7 +80,7 @@ namespace cwebplusApp.Pages {
if (addressDto == null) {
this.bicycleGeoPosition.Latitude = ReportDataProvider.GetFoundReport().GeographicInfo.Latitude;
this.bicycleGeoPosition.Longitude = ReportDataProvider.GetFoundReport().GeographicInfo.Longitude;
addressDto =await NominatimService.GetAddressForCoordinates(this.bicycleGeoPosition.Latitude, this.bicycleGeoPosition.Longitude);
addressDto = await NominatimService.GetAddressForCoordinates(this.bicycleGeoPosition.Latitude, this.bicycleGeoPosition.Longitude);
}
return GetFormattedAddressZipAndTown(addressDto);
}

+ 1
- 1
Shared/Services/BicycleRestService.cs Dosyayı Görüntüle

@@ -172,6 +172,6 @@ namespace cwebplusApp.Shared.Services {
return response;
}
}
}

+ 1
- 1
Shared/Services/IBicycleRestService.cs Dosyayı Görüntüle

@@ -16,7 +16,7 @@ namespace cwebplusApp.Shared.Services {
Task<ReportResponse> SendFoundReport(Report report);
Task<ReportResponse> SendFoundReport(FoundReportRepositoryItem reportRepositoryItem);
Task<ReportResponse> SendFoundReport(FoundReportRepositoryItem reportRepositoryItem);
Task<ReportResponse> SendMissingReport(Report report);

+ 26
- 34
wwwroot/service-worker.js Dosyayı Görüntüle

@@ -55,6 +55,7 @@ const assets = [
'https://fonts.gstatic.com/s/roboto/v27/KFOlCnqEu92Fr1MmEU9fBBc4AMP6lQ.woff2',
'https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2',
'https://fonts.gstatic.com/s/materialicons/v85/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2',
'https://fonts.gstatic.com/s/ubuntu/v15/4iCv6KVjbNBYlgoCxCvjsGyNPYZvgw.woff2',
'appsettings.json',
'manifest.json'
];
@@ -67,7 +68,8 @@ self.addEventListener('install', event => {
console.log('caching app assets');
cache.addAll(assets);
})
);
)
self.skipWaiting();
});
// activate event
@@ -85,42 +87,32 @@ self.addEventListener('activate', event => {
console.log('Now ready to handle fetches!');
})
);
self.clients.claim();
});
// fetch events (appsettings are always first fetched from network)
self.addEventListener('fetch', event => {
if (event.request.url.endsWith(appsettings_url)) {
fetch(event.request).then(function (response) {
return caches.open(staticCacheName).then(function (cache) {
console.log('update cache');
cache.put(event.request, response.clone());
return response;
});
}).catch(function () {
return useFallback();
});
} else {
event.respondWith(
caches.match(event.request).then(cacheRes => {
return cacheRes || fetch(event.request);
})
);
}
// fetch events (Network first strategy, no cache update after install)
self.addEventListener('fetch', function (event) {
event.respondWith(fromNetwork(event.request, 6000).catch(function () {
return fromCache(event.request);
}));
});
function useFallback() {
return Promise.resolve(new Response(Appsettings_Fallback, {
headers: {
'Content-Type': 'application/json'
}
}));
function fromNetwork(request, timeout) {
return new Promise(function (fulfill, reject) {
var timeoutId = setTimeout(reject, timeout);
fetch(request).then(function (response) {
clearTimeout(timeoutId);
fulfill(response);
}, reject);
});
}
var Appsettings_Fallback = {
"host_base_url": "https://integrate.dynalias.net:9443/Fundvelo/",
"subresource_url_colors": "api/{0}/{1}/fundvelo/colors",
"subresource_url_brands": "api/{0}/{1}/fundvelo/brands",
"subresource_url_types": "api/{0}/{1}/fundvelo/types",
"subresource_url_foundreport": "api/{0}/{1}/fundvelo/fundmeldung",
"subresource_url_missingreport": "api/{0}/{1}/fundvelo/suchauftrag"
}
function fromCache(request) {
return caches.open(staticCacheName).then(function (cache) {
return cache.match(request).then(function (matching) {
return matching || Promise.reject('no-match');
});
});
}

Loading…
İptal
Kaydet